Announcement

Collapse
No announcement yet.

Stuck on how to get collision working on parts of a character! :S

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Stuck on how to get collision working on parts of a character! :S

    Hi guys,
    So I'm trying to add collision to a character for a little fight game I'm attempting to make. Basically I'm adding static meshes to the character limbs/ sockets in code that will be made invisible in future. I want to make it so that if the various parts hit whilst performing an exec function then it will register some damage to an object. I can get the static mesh spheres for the collisions in place but the problem is I cant seem to get any physics on to them. What am I doing wrong??? I'm a total noob to coding so any guidance would be really appreciated.


    Getting the following warnings from compile when I try to do a collision component in the default properties.

    Code:
    warning, unknown property in defaults: Component.add(StaticMeshComponent) <looked in StaticMeshComponent>
    
    warning, unknown property in defaults: CollisionComponent=StaticMeshComponent<looked in StaticMeshComponent>
    my code is

    Code:
    var StaticMeshComponent Sphere;
    
    simulated function PostBeginPlay()
    {
            super.PostBeginPlay();
    	Sphere = new class'StaticMeshComponent'; //making the element to attach
    	Sphere.SetStaticMesh(StaticMesh'Monster_Mash.Sphere'); // directing to my static mesh to use 
            Mesh.AttachComponentToSocket(Sphere, 'Right_Hand'); // where i want it to connect to
            //SetPhysics(PHYS_RigidBody); //Doesn't work, character sinks in to ground and gets stuck!
            //CollisionComponent=Sphere; //Doesn't work!
            //bCollideWorld = true; //Doesn't work!
    }
    
    
    defaultproperties
    {
            Begin Object Class=SkeletalMeshComponent Name=GA_SkeletalMesh 
            SkeletalMesh=SkeletalMesh'Monster_Mash.fish_man' //character mesh
            AnimTreeTemplate=AnimTree'Monster_Mash.Fish_Man_Tree' // animation tree
            PhysicsAsset=PhysicsAsset'Monster_Mash.fish_man_Physics' // physics asset to use
            AnimSets(1)=AnimSet'Monster_Mash.Fish_man_anims' // animations to use
            Scale=1.75
            End Object
            Mesh=GA_SkeletalMesh
            Components.Add(GA_SkeletalMesh)
            
                   
            Begin Object Class=StaticMeshComponent Name=Hand_Sphere // 
                    Components.Add(StaticMeshComponent); // getting the errors here 
                    CollisionComponent=StaticMeshComponent // getting the errors here
                   // bCollideWorld=true
                   // bCollideActors=true
                   // bBlockActors=true
            End Object
           
    }
    Again, any help would be awesome, I'm proper stuck with this now!
    Cheers
    Matt

    #2
    So I'm still not having any joy with adding collision to my character, I've made a video to show what is happening.

    http://matts-gameworks.tumblr.com/
    The video saying collision not working!

    The idea is that I want to use spheres in conjunction with an exec function so that when triggered they will gain physics and do some damage, but when not activated they will not bump in to/ knock things over.

    The code that I'm using to connect and supposedly activate the spheres is this in my Pawn class

    Code:
    var StaticMeshComponent Sphere;
    var StaticMeshComponent Sphere1;
    
    simulated function PostBeginPlay()
    {
    
            super.PostBeginPlay();
            	Sphere = new class'StaticMeshComponent';
    	Sphere.SetActorCollision( true, true, true );
    	Sphere.SetBlockRigidBody( true);
            	Sphere.SetTraceBlocking( true, true );
                bCollideWorld = true;
            	Sphere.SetStaticMesh(StaticMesh'Monster_Mash.Sphere');
            	Mesh.AttachComponentToSocket(Sphere, 'Right_Foot');
    
    
     	Sphere1 = new class'StaticMeshComponent';
    	Sphere1.SetActorCollision( true, true, true );
    	Sphere1.SetBlockRigidBody( true);
    	Sphere1.SetTraceBlocking( true, true );
                bCollideWorld = true;
           	Sphere1.SetStaticMesh(StaticMesh'Monster_Mash.Sphere');
                Mesh.AttachComponentToSocket(Sphere1, 'Right_Hand');
    
    // adds spheres to the hand and foot of the mesh, 
    }
    Problem is no collision is occurring and the other objects in the scene are K-Actors so should be moveable.
    Any ideas? I'm pretty stuck with this!

    Cheers
    Matt

    Comment


      #3
      Help Needed!

      Ok, so I've had a minor breakthrough in the attachment of objects and collision. I'm able to attach elements to the correct socket and it show up in game with this code but the collision doesn't work!
      There's another video showing what's happening at
      http://matts-gameworks.tumblr.com/ called “Working but not quite!”
      The first part shows the following code and it's got some weird behaviour, like floating up in the air.

      Code:
      class Monster extends UDKPawn
              placeable; 
      var name Left_Hand, Right_Hand, Left_Foot, Right_Foot, Head; // Socket names
      
      var StaticMeshComponent Sphere;	// Mesh to use as collision component
      var StaticMeshComponent Sphere1; // Mesh to use as collision component
      
      simulated function PostBeginPlay()
      {
              super.PostBeginPlay();
      	Sphere1 = new class'StaticMeshComponent';
                  Sphere1.SetStaticMesh(StaticMesh'Monster_Mash.Sphere');
                  Mesh.AttachComponentToSocket(Sphere1, 'Right_Hand');
                  CollisionComponent = Sphere1;
                  AttachComponent(Sphere1);
                  Sphere1.SetBlockRigidBody( true);
                  Sphere1.SetTraceBlocking( true, true );
      }
      
      defaultproperties
      {
              Begin Object Class=SkeletalMeshComponent Name=GA_SkeletalMesh
              SkeletalMesh=SkeletalMesh'Monster_Mash.fish_man'
              AnimTreeTemplate=AnimTree'Monster_Mash.Fish_Man_Tree'
              PhysicsAsset=PhysicsAsset'Monster_Mash.fish_man_Physics'
              AnimSets(1)=AnimSet'Monster_Mash.Fish_man_anims'
              Scale=1.75
              BlockNonZeroExtent=true
              BlockZeroExtent=true
              BlockActors=true
              CollideActors=true
              End Object
              Mesh=GA_SkeletalMesh
              Components.Add(GA_SkeletalMesh)
      	
      	bCollideActors=True
              bBlockActors=True
              bCollideWorld=true
      }
      However in the second part of the video I've removed all the stuff from the PostBeginPlay function and added this to the default properties

      Code:
      class Monster extends UDKPawn
              placeable; 
      var name Left_Hand, Right_Hand, Left_Foot, Right_Foot, Head; // Socket names
      
      var StaticMeshComponent Sphere1; // Mesh to use as collision component
      
      
      Begin Object Class=StaticMeshComponent Name=Sphere1
              StaticMesh=StaticMesh'Monster_Mash.Sphere'
            End Object
              Components.Add(Sphere1)
      	bCollideActors=True
              bBlockActors=True
              bCollideWorld=true
      An enlarged sphere appears as it does in the socket manager before I set its scale and connection.

      It is doing what I want of knocking stuff over but the sphere is massive and in the wrong place!

      I've tried in vain to attach to the socket in the default properties and also trying to get the physics working in the PostBeginPlay function.
      I really need help! I'm so close to rage quitting on this project! What am I doing wrong? How come I can't set the collision? Is there a way to assign sockets in the default properties?
      Any help would be greatly appreciated
      Cheers
      Matt

      Comment


        #4
        components added with AttachComponent/AttachComponentToSocket will lose their collision, period. that's because it only ever attaches the mesh component.
        then by doing CollisionComponent = Sphere1; I believe you're telling your Pawn that its Collision Component will be the new Sphere but it loses the old collision component, so it will not work for adding multiple spheres

        an alternative would be to create your spheres by using Spawn() and then use SetBase() instead

        Comment


          #5
          Thanks Chosker,
          I'd have ripped my hair out trying to get the other method to work. You've given me a new direction to try!
          Cheers
          Matt

          Comment


            #6
            no problem. good luck!

            one thing to notice: using SetBase will make the attached actor lag 1 frame regarding the other actor. depending on the speed of your game it might or might not be noticeable, but in my experience anything that lags 1 frame will be visible if you move somewhat fast (ie. run) and run the game at less than 30 fps.
            I know your collision shapes will be invisible but the gameplay depends on them, and 'important to gameplay' and 'framerate dependant' make up a pretty bad combination.
            I'm not sure but changing the TickGroup might solve it

            Comment


              #7
              Originally posted by Chosker View Post
              I'm not sure but changing the TickGroup might solve it
              This. It shouldn't lag if tickgroups are correct.

              Comment


                #8
                Originally posted by Chosker View Post
                components added with AttachComponent will lose their collision, period.
                I'm pretty sure the PrimitiveComponents I've added with AttachComponent collided properly. 'AlwaysCheckCollision' is set to true for them though.

                Comment


                  #9
                  If attachComponent is used , the owner of the collision component , it's set to the actor that has been attacched to ...

                  Example

                  you attachcomponent to a pawn , now if you hit that component collision , the owner will be pawn , even if the collision component was of the actor sword ...

                  How to get to not have this issue setBase , problem in multiplayer does not work """ correct me if im wrong """ !

                  Comment


                    #10
                    Hi guys, thanks for the input
                    Well I've been trying to set up the Spawn and SetBase features, I'm getting nowhere with it! I've spent the last 2 days trying to get it to work and I am totally flummoxed and demoralised by the process. I've got to admit there are parts of unrealscript I can understand but I'm loosing the will to live with this now. Guess this is what happens when an artist tries to learn programming!

                    I've tried to SetBase to be my skeletal mesh but it comes up with

                    Error, Bad or missing expression in Call to 'SetBase' , Parameter 1

                    My code is this
                    Code:
                    var SkeletalMeshSocket Left_Hand, Right_Hand, Left_Foot, Right_Foot, Head;
                    var SkeletalMeshComponent Monster_SkeletalMesh;
                    
                       simulated function PostBeginPlay()
                    {
                          //local Pawn M; 
                           super.PostBeginPlay();
                    
                            //M = Monster_SkeletalMesh(Instigator);
                            //Sphere1 = StaticMeshComponent;
                    
                            if (Monster_SkeletalMesh != None)
                            {
                                Monster_SkeletalMesh = Mesh; // Monster skeletal mesh
                                Spawn(Class'Monster_Sphere', Self, , , ); // class/ owner/ Tag/ Location/ Rotation
                                SetBase(MonsterPawn,,M.Mesh,Right_Hand);
                                //Sphere1.SetCollision(true, true);  // doesn't like the '.' after sphere
                                //Sphere1.SetHardAttach(true);
                               //archetypeReference=StaticMeshActor'Monster_Mash.Sphere1A'
                            }
                    }
                    code for the spawnable sphere

                    Code:
                    Class Monster_Sphere Extends Actor
                            Placeable;
                    
                    defaultproperties
                    {
                         Begin Object Class=StaticMeshComponent Name=Monster_Sphere
                            StaticMesh=StaticMesh'Monster_Mash.Sphere'
                            Scale=0.2
                            BlockNonZeroExtent=true
                            BlockZeroExtent=true
                            BlockActors=true
                            CollideActors=true
                         End Object
                            Components.Add(Monster_Sphere)
                            bCollideActors=True
                            bBlockActors=True
                            bCollideWorld=true
                    }
                    Please help!!! I don't want a step by step solution but I do need pointers on what is wrong as I am stuck and have no idea how to fix it! Any help would be massively appreciated!
                    Cheers
                    Matt

                    Comment


                      #11
                      One step closer! I think :S

                      Ok, so I though I'd have another go at getting this sphere to connect to the mesh using Spawn and Set base.
                      After finding this thread I've substituted my own bits in to the setup.
                      http://forums.epicgames.com/threads/...a-Socket/page3

                      To make an archetype I followed this tutorial,
                      http://romerounrealscript.blogspot.c...ealscript.html
                      Though I found I couldn't get it to acknowledge it in the code so I made a new script called Monster_Sphere and used that instead

                      Code:
                      Class Monster_Sphere Extends Actor
                              Placeable;
                      
                      defaultproperties
                      {
                           Begin Object Class=StaticMeshComponent Name=Monster_Sphere
                              StaticMesh=StaticMesh'Monster_Mash.Sphere'
                              Scale=0.2
                              BlockNonZeroExtent=true
                              BlockZeroExtent=true
                              BlockActors=true
                              CollideActors=true
                           End Object
                              Components.Add(Monster_Sphere)
                              bCollideActors=True
                              bBlockActors=True
                              bCollideWorld=true
                      }
                      I've altered my code in the Pawn class for my monster and that all compiles and there are no errors
                      Code:
                      class Monster extends UDKPawn
                              placeable;
                      
                      var name Right_Hand;
                      
                      simulated function PostBeginPlay()
                      {
                      local Vector SocketLocation;
                      local Rotator SocketRotation;
                      local Actor Sphere1;
                      
                              if (mesh != None)
                              {
                                      if (/*SphereArchetype != None &&*/ mesh.GetSocketByName(Right_Hand) != None)
                                      {
                                      mesh.GetSocketWorldLocationAndRotation(Right_Hand, SocketLocation, SocketRotation);
                      
                                      Sphere1 = Spawn(Class'Monster_Sphere' ,,, SocketLocation, SocketRotation);
                                      `log("------------------------------------the Sphere has spawned");
                      
                                              if (Sphere1 != None)
                                              {
                                              Sphere1.SetBase(self,, mesh, Right_Hand);
                      
                                              }
                                      }
                              }
                      }
                      So I feel like I am making some progress but the problem I've got now is that even though it compiles without any errors, the sphere is not showing up.
                      Any ideas/ suggestions??
                      Cheers
                      Matt

                      Comment


                        #12
                        Solved!
                        I needed to put ' ' around the socket I wanted things to spawn from!

                        Comment


                          #13
                          I originally used SetBase for the loadout system in Ground Branch. Not wanting to rely on this for in-game loadouts (updated X actors is more expensive then X components), I investigated AttachComponent more. I found that to be able to trace the items:
                          • Attached items must have an owner.
                          • bCollideActors must be TRUE for the base actor.
                          • CollideActors must be TRUE for the mesh.
                          • BlockZeroExtent must be TRUE for the mesh.

                          [screenshot]http://www.groundbranch.com/wp-content/uploads/2013/03/dev_ingame_20130331a.jpg[/screenshot]

                          In this case, the owner is set to the base actor on spawn and the collision component is set after attachment to the socket.

                          As far as I am aware, collision calls would work too, provided the right settings are used. As such, I was going to investigate this further to see if I could use it as an alternate method for detecting weapon collision.

                          Perhaps it is something you could look in to?

                          Comment

                          Working...
                          X