Setting a Scene Object's Velocity After a Collision
by Sean Monahan · in Torque X 2D · 11/19/2009 (2:35 am) · 4 replies
This has been a bit of a nagging problem for me so I thought I'd post here to see if anyone has any thoughts.
I'm currently working on a couple of components that use collisions to deal damage to enemies. One is a grenade component and the other is a melee component that allows for punching and grabbing/headbutting. Both these components work by processing collisions. The grenade explodes and it's collision polygon expands, damaging anything it collides with. A similar process happens with the melee attack.
The problem I have is that I want to set the damaged objects' velocity after the collision to simulate them being hit with a strong force. Presently I set each damaged object's velocity with something like this:
However the object's never move that far. Also, if I set the velocity with a negative x value I'd expect them to move to they always move to the right. This leads me to believe that one of two things is happening:
1) I'm doing this wrong
2) There is some default behavior that I need to disable/override
Does anyone have any advice on how I should proceed?
I'm currently working on a couple of components that use collisions to deal damage to enemies. One is a grenade component and the other is a melee component that allows for punching and grabbing/headbutting. Both these components work by processing collisions. The grenade explodes and it's collision polygon expands, damaging anything it collides with. A similar process happens with the melee attack.
The problem I have is that I want to set the damaged objects' velocity after the collision to simulate them being hit with a strong force. Presently I set each damaged object's velocity with something like this:
damagedObject.Velocity = new Vector2(1000, 0); // Should shoot off to the right
However the object's never move that far. Also, if I set the velocity with a negative x value I'd expect them to move to they always move to the right. This leads me to believe that one of two things is happening:
1) I'm doing this wrong
2) There is some default behavior that I need to disable/override
Does anyone have any advice on how I should proceed?
#2
I think what is probably going on is that you are using the ResolveCollision property of the T2DCollisionComponent. The ResolveCollision working by altering the velocity of the object.
This way, it won't matter what velocity you have set, the collision respone will override it. Try to set ResolveCollision to "None" and SolveOverlap to false for your blast poligon.
11/20/2009 (6:03 pm)
This is strange Sean, it should be working, you are doing it right.I think what is probably going on is that you are using the ResolveCollision property of the T2DCollisionComponent. The ResolveCollision working by altering the velocity of the object.
This way, it won't matter what velocity you have set, the collision respone will override it. Try to set ResolveCollision to "None" and SolveOverlap to false for your blast poligon.
#3
Thanks for the tips. Unfortunately, neither of them exactly works. ApplyImpulse rockets objects across the screen, it's just very unrealistic. Marking ResolveCollision off didn't help either. I think my problem is that, somehow, I'm setting the velocity elsewhere, thus overriding the velocity set by the collision.
I'll be trying to get to the bottom of this over the holiday and will post back when I get a solution.
11/23/2009 (12:44 pm)
Hey Guys,Thanks for the tips. Unfortunately, neither of them exactly works. ApplyImpulse rockets objects across the screen, it's just very unrealistic. Marking ResolveCollision off didn't help either. I think my problem is that, somehow, I'm setting the velocity elsewhere, thus overriding the velocity set by the collision.
I'll be trying to get to the bottom of this over the holiday and will post back when I get a solution.
#4
I'm not running on a lot of sleep right now, but...
I think it's just order of operations soo.
so set your new vector in a variable first.
this will be your direction only.
call it "vector_right" or whatever and have it equal the new vector(1,0);
then set your object.velocity = vector_right * [speed variable];
speed variable might need to be set high, depending on your scale of units used.
12/08/2009 (5:17 pm)
the vector(1000,0), I think, is the same as the vector(1,0).I'm not running on a lot of sleep right now, but...
I think it's just order of operations soo.
so set your new vector in a variable first.
this will be your direction only.
call it "vector_right" or whatever and have it equal the new vector(1,0);
then set your object.velocity = vector_right * [speed variable];
speed variable might need to be set high, depending on your scale of units used.
Torque Owner Christian Rousselle
Default Studio Name