Hi,
I couldn't find on the forums if something like :
- align object's X axis to the stage's Y axis
- align turret's cannon X axis to enemy's direction
- align character's Y axis to the normal of the object/polygon that he is walking on
- send ray (rayCast(to, from, distance, property, face, xray)) from the character to the platform he is walking on
- get the normal at the hit's position
- Align the character's y axis to the normal
I couldn't find it something that would make those operations easier was available as a Class, built around a Vector's class.
Notes :
- Box2D's raycast doesn't seem to return hit normal
- This discussion was
very helpful but didn't cover all my questions
For example in blender's
3d Game Engine it's used like this :
alignAxisToVect(vect, axis, fac)
Aligns a Game Object axis to a World vector.
vect: Uses the World axis as it's base reference.
Type: 3D Vector
examples:
[ 1.0, 0.0, 0.0] = World X-axis
[ 0.0, 1.0, 0.0] = World Y-axis
[ 0.0, 0.0, 1.0] = World Z-axis
axis: Game Object axis
Type: integer
0 = Game Object x-axis
1 = Game Object y-axis
2 = Game Object z-axis
fac: Determines the "speed" of the alignment over multiple frames.
Type: float
Range: 0.0 to 1.0
0.0 = no movement
1.0 = instantly |
I think that some will suggest that it's not that hard to built it myself, but I would rather use something done by a skilled programmer than reinvent the wheel (and break it in the process) if possible
Thank you
Comments
As far as I understand from your post, I've prepared a simple example that aligns a sprite to a vector. It uses math.atan2 to find the alignment angle and transforms the box. (after running the program, drag a line on the screen).
btw, does your game uses box2d? or do you try to use box2d just to align a sprite to a vector?
That's exactly what I was trying to achieve, I should be able to make it work like a 2D Mario Galaxy with some work.
I believe it would be great to wrap and abstract this behind an alignAxisToVect() and add it to Gideros Studio in the future.
This would make it easier for all kind of ai (align car to the road's direction with an additional alignment speed parameter), make npc walk in the player's direction), make a character stick to a surface (Mr. Ninja, Mario Galaxy 2d) etc...
My game doesn't use box2d, I was just trying to find out how Gideros implements raycasts but it seems it can be achievable only through box2d?