Collision with player with PSK
by M.B. · in Torque X 2D · 06/20/2010 (6:21 pm) · 13 replies
I noticed that when adding an object with collision and physics applied to it the player does not interact with it properly in the platform starter kit. Is this something I'm doing wrong? All im trying to do is add a box that is pushable and in a regular torque x project this works fine but in the platformer kit the box moves when the player touches it but when the player jumps on it the just slides to the left or right. Something seems really weird.
Anyone know how I can solve this?
Anyone know how I can solve this?
About the author
#2
06/21/2010 (9:29 pm)
I tried that but then the object loses all physics properties???
#3
06/22/2010 (4:51 am)
You may well need to create a custom platform type or mess with the psk code. 'platforms' with physics properties is something that is on my list, but I haven't got to it yet so I'm afraid I can't really offer anymore advice than that at the moment.
#4
06/25/2010 (10:20 pm)
hmmm I'm wondering what the reason was to not just make the payer a regular physics object in the platformer kit. Seems weird to cut out all physics object interaction? I cant really see a reason why someone would have done this but I'm going to dig into that part of the code this weekend a bit so maybe I'll find out :S
#5
06/26/2010 (4:50 am)
ActorComponent._updateOnGround() is a good place to start.
#6
07/01/2010 (12:55 pm)
So been looking into this more... And I still cant figure out why when applying a force to a platform it doesnt move at all :(
#7
This sets the object as immovable.
07/01/2010 (1:58 pm)
In SolidPlatform::_OnRegister()if (_platform.Physics != null)
_platform.Physics.InverseMass = 0;This sets the object as immovable.
#8
07/01/2010 (4:47 pm)
My guess is you are trying to create a block you can push around, and stand on, is that correct? I'm not sure thats a default behavior, you'd have to mess around a bit to get something to do that. Platformer physics is totally different then normal physics, but most of what the platformer physics does is ripped right out of normal physics operations, so the solution could be as simple as setting the OnCollisions for your box properly, maybe come up with a custom on collision, or extend the "solid platform" then set the type properly, perhaps? But I don't know, you'll have to mess around with it a bit.
#9
and I wrapped the the stuff Duncan mentioned in an if statement
This seems to be putting me in the right direction. But it seems like the player still kicks it around like hollow ballons even if I crank up the mass. I guess its because the Actor class updated hte players position directly with the X and Y instead of moving it around by applying force to the actor?
Thats my guess anyways. Not 100% sure how to tackle that yet.
I really am digging torqueX though. After I get this and 2 more small things working I can start dominating the level editor :D
07/01/2010 (9:52 pm)
well I added a new variable to the solidPlatfor class called hasPhysicsand I wrapped the the stuff Duncan mentioned in an if statement
if (_hasPhysics == false)
{
_platform.Collision.CollidesWith = PlatformerData.PlatformTriggerObjectType;
if (_platform.Physics != null)
_platform.Physics.InverseMass = 0;
}This seems to be putting me in the right direction. But it seems like the player still kicks it around like hollow ballons even if I crank up the mass. I guess its because the Actor class updated hte players position directly with the X and Y instead of moving it around by applying force to the actor?
Thats my guess anyways. Not 100% sure how to tackle that yet.
I really am digging torqueX though. After I get this and 2 more small things working I can start dominating the level editor :D
#10
07/01/2010 (10:16 pm)
Hmmm bit of a correction to my last post. Seems like objects that have the ResolveCollision set to rigid are the ones that dont seem to behave right when interacting with the player. The other ones seem to be acting more like expected? Now I'm confused haha maybe becauses it late :S
#11
07/01/2010 (10:41 pm)
Oh yeh and Will sorry I guess I didnt answer your question haha Yes I'm trying to make pushable boxes aswell as pillars that you can push over.
#12
That line of code is interesting.. I think you want to see if it collides with the player.. I think I have a solution for you. This might take some fiddling around to get it right.. I would do it by only modifying the player... Heres a snippet of code I use to check the normal of the collision... you can perhaps use something similar to this to tell if the colliding object how you want it to behave.
07/01/2010 (11:33 pm)
_platform.Collision.CollidesWith = PlatformerData.PlatformTriggerObjectType;
That line of code is interesting.. I think you want to see if it collides with the player.. I think I have a solution for you. This might take some fiddling around to get it right.. I would do it by only modifying the player... Heres a snippet of code I use to check the normal of the collision... you can perhaps use something similar to this to tell if the colliding object how you want it to behave.
public virtual void ActorHitWall(ActorComponent actor, T2DCollisionInfo info, float dot)
{
if (Math.Abs(info.Normal.X) > Math.Abs(info.Normal.Y))
{
//possible some code here
//such as if "player hitting "B" " and to left. move block right, if player hitting B and to right, move block left, etc" you can tell if you are left or right, if the normal.X is pos or neg.
}
}
#13
Try implementing your own resolve collision - in there you can take account of the object's 'weight' yourself. You can copy and modify the existing collision resolve functions as a starting point.
07/02/2010 (7:54 am)
Quote:
the player still kicks it around like hollow ballons
Try implementing your own resolve collision - in there you can take account of the object's 'weight' yourself. You can copy and modify the existing collision resolve functions as a starting point.
Torque Owner Duncan Colvin