T2DForceComponent and default MovementComponent
by Jake Davis · in Torque X 2D · 08/20/2009 (6:31 pm) · 4 replies
Okay, here is what I have tried:
1. Create new Starter Game 2D project.
2. Start and run game and I can move the GG logo around the screen as expected.
3. Add T2DForceComponent to the GG Logo object. Add Massless Force with Mix, Max and Initial set to 26.00, ConstantDirectionIsWorldSpace checked and constant direction set to 0.00.
4. Start and run game - expecting GG logo to start to fall to bottom of screen. It just sits there and I can still move around.
5. Remove MovementComponent from the GG logo, start and run game, GG logo falls to bottom of screen as expected.
It seems that the movement component is overriding the force component's changes to Velocity.Y and setting it to 0.00 when I'm not moving the object. Is this the expected behavior?
1. Create new Starter Game 2D project.
2. Start and run game and I can move the GG logo around the screen as expected.
3. Add T2DForceComponent to the GG Logo object. Add Massless Force with Mix, Max and Initial set to 26.00, ConstantDirectionIsWorldSpace checked and constant direction set to 0.00.
4. Start and run game - expecting GG logo to start to fall to bottom of screen. It just sits there and I can still move around.
5. Remove MovementComponent from the GG logo, start and run game, GG logo falls to bottom of screen as expected.
It seems that the movement component is overriding the force component's changes to Velocity.Y and setting it to 0.00 when I'm not moving the object. Is this the expected behavior?
#2
You can stop this by adding a boolean check before the velocity is set.
Or you can even have it so the object is being pushed around only when the sticks are not moving.
Pretty much, your force won't work very well if you're setting velocity to create movement with the movement component.
Hope this helps.
08/24/2009 (3:24 am)
The reason for this is that every tick, the movement component is setting the exact velocity on the GG logo. There is no way a force can push something if every tick the velocity is being set to 0 (or whatever the sticks value is).You can stop this by adding a boolean check before the velocity is set.
if(canMove == true){
// set our test object's Velocity based on stick/keyboard input
_sceneObject.Physics.VelocityX = move.Sticks[0].X * 20.0f;
_sceneObject.Physics.VelocityY = -move.Sticks[0].Y * 20.0f;
}Or you can even have it so the object is being pushed around only when the sticks are not moving.
if(move.Sticks[0].X != 0 && move.Sticks[0].Y != 0){
// set our test object's Velocity based on stick/keyboard input
_sceneObject.Physics.VelocityX = move.Sticks[0].X * 20.0f;
_sceneObject.Physics.VelocityY = -move.Sticks[0].Y * 20.0f;
}Pretty much, your force won't work very well if you're setting velocity to create movement with the movement component.
Hope this helps.
#3
08/24/2009 (4:40 pm)
Thanks for the reply Cosmic. I pretty much figured that is what was happening. I was hoping that under the covers, the physics would be applied to the object after any other updates were done...guess not. Do you know what the PreUpdateForces and PostUpdateForces methods are for on the force component?
#4
08/26/2009 (12:04 am)
Not entirely sure, sorry. I just started up with X# and TX in June. Hopefully somone else will be able to tell you.
Torque Owner Jake Davis