|
Greetings, Can I add velocity to an object relative to it's local axis? This is the snippet of code: But it's relative to the world, I want it to be relative to the local object. Here is the full script.
(comments are locked)
|
|
Convert the current velocity to local space, modify the z component and convert it back to world space: But if you just want to add/subtract a velocity in the forward direction, use transform.forward: It works, but halfly. The velocity total doesn't follow the fix value and provoke a slingshot effect.
Dec 09 '11 at 12:06 AM
Oninji
You're modifying only the z local component, what alters the magnitude and the direction; furthermore, transform.forward and rigidbody.velocity may have completely different directions - thus local space (a transform related concept) may not be what you're looking for.
Dec 09 '11 at 02:34 AM
aldonaletto
I want to move the object on a constant pace toward it's own rotation. Thus I want to control velocity through the script and keep it's x,z velocity equal to the MovSpeed variable. I also thought of translating the Y rotation degree into X,Z distribution value (ie 90Y rotation = 0.5x + 0.5z), the distribute the total velocity wanted (MovSpeed) to the x and z velocity. But I'm not sure it's the best way to accomplish this.
Dec 10 '11 at 11:47 PM
Oninji
I suppose that this may be what you're looking for: If you rotate the object, transform.forward follow the direction change, thus this should do what you want. It's advisable to set rigidbody.freezeRotation to true - the object still can be rotated, but physics rotational effects will be disabled, avoiding weird reactions to collisions.
Dec 11 '11 at 01:40 AM
aldonaletto
Yes, it behaves exactly how I wanted. Better then my patch-up where I've translated Y rotation to X,Z using Cos and Sin maths. Erf, and just saw I've used a similar code in an old project, just didn't saw the relation. Anyway, thank you very much sir.
Dec 12 '11 at 02:04 AM
Oninji
(comments are locked)
|
