- Home /
How to use something like SLERP but with continuous physics
Hey there. I am having a little trouble with my slerp function at the moment. When you hold down the X button on the controller you can zap a target towards you and when i reaches abotu 5 meters away from you it stops and you can then control the object around you in an arc by using SLERP and the controller joysticks.
The only issue i am having is that the physics are gone as soon as it enters the SLERP function. I have seen some pointers on the forums saying that because I am directly changing the objects position the physics are cancelling out. Is there any way to use something like SLERP for the arc type effect I am trying to achieve but with Physics attached?
Here is a quick diagram to illustrate what I am trying to do:
And here is my SLERP function: //controls the arc that the object is kept in void slerpFunc() {
float damping = 2;
//limits the Slerp function to the centre point of Roybot
//sets up 3 vectors the start position and the end position for the interpolation
//and the center point
Vector3 centre = transform.position;
Vector3 startPos = transform.position + new Vector3(0,0,5);
Vector3 endPos = transform.position + new Vector3(0,0,-5);
centre -= Vector3.up;
Vector3 startRelCentre = startPos - centre;
Vector3 endRelCentre = endPos - centre;
//I am overriding the physics with transform.position. Need to find a better way to do this!!
target.transform.position = Vector3.Slerp(startRelCentre, endRelCentre, rightThumbValueY/damping);
target.transform.position += centre;
}
If anyone has come across this before or can help in any way it would be much appreciated!
Cheers :)
I saw an interesting suggestion go by on this list concerning this issue, but I'm out of town and cannot test it. The idea was to move an empty game object and attach the physical game object to the empty game object using a spring joint.
Answer by gharbill · May 06, 2013 at 04:57 AM
If you want to maintain physics you have to do it physically A simple trick can be creating a high gravity source like a magnet object which can be controlled by your slerp and then assigning the rgidbody you want to controll to be affected by that magnet. Tell me if it worked ;)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
collision with objects, physics 1 Answer
Having trouble with Physics.IgnoreCollision(). 1 Answer
Fist Passing Through The Target 2 Answers
RAYCAST KNOWLEDGE HELP!!! 1 Answer