0
\$\begingroup\$

I try to make an object rotate around another object on mouse input. In order to achieve this I used this code:

transform.RotateAround(objectToRotateAround.transform.position, Vector3.back, Input.GetAxisRaw("Horizontal") * Time.deltaTime * speed);

I use GetAxisRaw because the movement has to be precise (the game that I am making requires a lot of reaction).

The problem is the shield movement doesn't feel good. I would like to be able to add a little bit of friction to the movement.

A solution that would enable me to tweak certain aspects of the rotation would be ideal. Any kind of guidance or documentation that might help is also very well-received 😄.

PS: I also tried to work with Quaternions. This was the code that I've tried.

 Vector3 relativePos = objectToRotateAround.transform.position - transform.position;
 transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(relativePos,Vector3.forward), Time.deltaTime);
 transform.Translate(0, 0, Input.GetAxisRaw("Horizontal") * Time.deltaTime * speed);

There are a few problems with this code.

The Quaternion.LookRotation rotates my object on all 3 axes instead of the Y-axis. I think even if the object rotates properly, the Translate method will make it move the same as the previous solution. Thank you for your time and attention. I really appreciate it.

New contributor
Paul Berta is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
2
  • \$\begingroup\$ have you tried manipulating the speed variable in the original rotation? Whatever effect you want to add to the rotatation it'll have to manipulate the value of Input.GetAxisRaw("Horizontal") * Time.deltaTime * speed. Try multiplying it by Mathf.sin(Time.time) //note: not deltatime , it will feel even worse but it might give you an idea about how to implement "friction" (not sure what you have in mind). \$\endgroup\$ Jun 19 at 12:03
  • \$\begingroup\$ Thank you for your comment. This gave me an idea. I used a parabola function and I passed in as an argument the GetAxis value. It basically does the same thing but now I can control the speed(acceleration) behavior via some parameters of the parabola generating function. \$\endgroup\$
    – Paul Berta
    Jun 20 at 10:18

0

You must log in to answer this question.

Browse other questions tagged .