I need help- Finding the direction of a moving obj

Blitz3D Forums/Blitz3D Beginners Area/I need help- Finding the direction of a moving obj

CodeOrc(Posted 2005) [#1]
Hey Everybody,

Ok, I have no hair left as I have yanked it all out trying to figure this out, now I am left with my own stupidity.

How can I find the direction of an object? An example would be- I have my charcater walking down a hallway, an object shoots out from a wall from his left.

Now, how do I determine that the object came from his left, then have my character "bump right" as a result from a hit to the left?

Ugh! Any help would be GREATLY appreciated.


big10p(Posted 2005) [#2]
The object coming from the left - or wherever - will have a motion vector i.e. the amount you're moving the object each time in the X,Y,Z directions. Just add that vector (or a fraction of it) to you're character's X,Y,Z movement when a collision occurs.


CodeOrc(Posted 2005) [#3]
Forgive my lack of experience, but was is the Syntax to find the Motion Vector?

thanx


big10p(Posted 2005) [#4]
I was a bit unclear. :) What I mean is: somewhere in your code you're moving the object coming from the left with MoveEntity ent,x,y,z or whatever, right? Well, take those x,y,z values and add them to your character's movement when a collision occurs.


CodeOrc(Posted 2005) [#5]
Thanx for your help big10p. But I need a little more clarification.

Ok your right, I can add the x value of my object moving to the left, but what if my character is making his way back through the hallway...now the object is hitting him from the right.

What I am trying to figure out is, no matter what angle my character is hit by, I need him to move accordingly.

So actually, the x and the z values would change, but depending on how the character is pushed. Is there an easy way to handle this no matter the case?

:::perfect world:::
MotionVectorEntity (wall_object)= left-right-forard-back
:::end perfect world:::

Does B3D have a command(s) that can determine this?

thanx again.


big10p(Posted 2005) [#6]
OK, it's difficult for me to say exactly how best to handle this as I don't know what method you're using to move things around in your game with. Specifically, if you're using global movement (TranslateEntity) or local movement (MoveEntity), or a combination of the two. :)

Basically, a solution may involve having to convert the motion vector of the object coming from the left, into the character's coordinate space. This can be done using the TFormVector command. It's not as difficult as it may sound and will ensure your character is pushed in the correct direction, regardless of which direction he/she/it is hit from.


PowerPC603(Posted 2005) [#7]
You can also use the command TranslateEntity to move the pushing object.
This way the vectors are in a global scale, so they do not depend on the direction your pushing object is pointing.

When the pushing object hits your player character, then also use TranslateEntity on your character with the same values as the pushing object.

This way the character will be pushed in the direction that the pushing object is moving, without any interference by the direction either object (pushing object or character) is facing.

Imagine a cube that's located at coordinates -5, 0, 0.
So in 3D space this object is located a bit to the left from the center of 3D space.
This cube is your pushing object.

Then your player is located at 0, 0, 0, facing any direction.

You Translate that cube to the right:
TranslateEntity cube, 0.1, 0, 0

When it hits your player character, also do:
TranslateEntity Player, 0.1, 0, 0

This way both the cube and player are moving the same global direction, as seen from the 3D space center.

See the TranslateEntity command documentation for further details.


_PJ_(Posted 2005) [#8]
Simple, maybe long-winded solution?

Would it be possible to have say 4,6 or more Pivot objects around your entity and check for collision with these?

The Pivots could perhaps be named 'Up', 'Down' 'Left' etc. Dunno, just a basic approach to the problem!


Rob Farley(Posted 2005) [#9]
OK... I posted this on another thread....

Personally I use a pivot to deal with forces I find it much easier to move things around etc. This way you don't need to worry about a whole load of stuff and it just works!

EG:


This has the added bonus that if you want to apply wind for example you just move all the physics pivots in the wind direction.

Same Example with a wind pivot:


So where I've got the wind example above, you'd have your object coming from the side being handled by it's own physics pivot, then when the object collide you just get the positions of the physics pivots and just move your player physics pivot say half the xyz components of the other physics pivot, job done, your guy will automatically move/get shoved etc without doing anything more than moving a pivot.

So that's my cheat physics solutions to pretty much everything!


CodeOrc(Posted 2005) [#10]
Awesome!

Thanks for the help everybody...I have a working example based on all input from the responses that I think will work.

Thanks!