I want the cube “Playerbox example” to go in a straight line of the pipe on top, when the player box touches the plane with the 3d cursor on it, it will go to a PIPE CLIMB STATE.
The player will then shimmy across the bar to the other side, but the problem is if the character
is slightly off axis, it will go away from the other platform.
Any ideas how to keep in straight line all the time.
No, you probably need to have a seperate state,
And you will probably need to add more
import bge
from mathutils import Vector
cont = bge.logic.getCurrentController()
own = cont.owner
Ray = cont.sensors['Ray']
if Ray.positive:
own.alignAxisToVect(Vector(ray.hitNormal),2,1)
This will line up the up axis to the plane, but you need to face forward/backward etc
You can get a local axis out of the hitObject like this
direction1 = Ray.hitObject.worldOrientation.col[0]
What you’re actually asking (I think) is to align the player direction to the bar that spans the gap between the platforms. You are essentially intending on creating a constraint. You can probably use a BGE constraint, or do it using Python. If the path is always straight, do the following:
Find the end and start points, and subtract the start from the end to get the direction (normalize this).
Align the player direction using alignAxisToVect (or find the alignment matrix (Y is the direction vector, X is the cross product between the direction and the world Z (in that order) and Z is the cross product between the X you found and the direction). This is the new worldOrientation matrix.
To move the player, add a position delta along the direction (own.worldPosition += direction * displacement). You would need to handle the fact that gravity will move the player.
That blend is exactly what i need. It`s just implementing it now, how would it work with a state.
When my character reacts to that plane on the floor, he goes into a state so he can do the action.
I put on first state (main movement) the Ray and Time.
Once ray has been hit, it will change to Pipe grab state, once its aligned because the ray has to hit for the state to change. ?? BPR thanks once again i hope this is working 100%
and then count down back to 30 while aligning the player worldPosition
I’ll take a look at it tonight, but basically, when you get under the bar, it will always ‘nudge’ the actor into the right place/ world position, to make it 100% the same each time you use it.
I localize the player position to the bar, so the x axis I check against is local to the pipe, I only check this one time and store it, when you climb off the value is cleared when the cloxk runs out.
I have ladders in my game too, and they basicly just switch a property that allows you to control the character, if that property is off, the ladder can fully remote the character ( climbing action, move it up ). I use collision sensor for it, it works really well and prevents wrong offset