Forward is always forward

Hi all,

I currently have a kinematic body that I rotate and I wish ‘forward’ to always be a positive y on the joystick (actually touch pad).

Vector3 pos=p.bodyhit.transform.position+(p.bodyhit.transform.TransformDirection(Vector3.forward) * ver);

Here’s what I currently do. ‘p’ is the parent and bodyhit is the rigidbody.
It would seem though that depending on my point of contact I’m not doing it correctly.
Hope my rather bad question is clear - any help/suggestions appreciated


Thanks - will add the delta time.
I think this problem is related to my other question - appreciate your response though


I am new to Unity, too, but I think the easiest way to do something lake that would be to parent your object to an empty and move that one forward, while rotating the child. At least that’s how I’d do an animation like that in Max, but I guess it should work in Unity, too.

Not sure about your scene setup, but I guess you want the character to always move forward, based on your cameras transformation:

float velocity = 0.1f * moveJoystick.position.y;
p.bodyhit.transform.position += Camera.main.transform.forward * velocity;


Thanks for the info.
I can’t use the camera ‘forward’ as the camera is all over the place :slight_smile:
I guess another way to phrase it is:

When my player collides with the cube. I wish the cube’s forward to be perpendicular to it but facing in the same direction as the cooling player. Erm, not sure if that helps :-))


I’m confusing myself.

I’ll explain what I want in real terms :-)))
I have a cube, I wish it to move in the direction that’s appropriate based on which side receives the collision. So hit the south face it should move north, hit the east face it should move west. My colliding body can obviously hit any of the 4 faces at any angle, equally the cube’s ‘forward’ could be anywhere i.e. the cube could be rotated around the y (up) axis.
So I am trying to create a new ‘forward’ vector so that I can move the cube in the appropriate direction.

Forgive my lack of knowledge and confusion; does this help?


No problem, but please first of all, comments are comments and answers are answers. You should not use the answer form, if you want to just leave a comment :wink:

Secondly, a vector A is perpendicular to vector B if their crossproduct is zero (90 degrees angle). A vector facing the opposite direction is simply called the inverse vector.

I guess you want to create some kind of bouncing behaviour?
Ideally you actually want to use the physics engine to get realistic behaviour of collisions. But if not you can use a simplified formula like:

Vector3 direction = (transform.position - collision.hitpoint).normalized;

where the transform is the Transform of the cube.

Cheers, Tommy