Trying to move an object in an arc around the player


I am trying to get my sort of gravity gun to work. The aim is to have the player draw an object (tractor beam style which i have working) and then to allow him to rotate the object around him to protect himself and then fire it off into certain directions.

You are going to be able to control the arc by using the XBOX right analog stick. The issue i am having is getting the object you have in your tractor beam to be controlled in an arc manner by actually using the right analog stick.

I have tried using rotate around but this is a fixed rotation and i need it to be updated in real time. Here is some of my code and explanations as to why i have used certain bits.

This line assigns the value of the right sticks to a variable to control the object and multiplies it by 360 to gain a 360 degree rotation of the thumb sticks:

rThumbArc = (Input.GetAxis("360_LThumbButton_X") - Input.GetAxis("360_LThumbButton_Y")) * 360;

This function is where i am struggling. I have tried RotateAround which gives me good results except i cannot control it with the thumbstick:

target.transform.RotateAround (currentPlayer.transform.position, Vector3.left, 100 * Time.deltaTime);

I then looked into circle geometry and found some pretty solid information about how to calculate points on an arc of a circle so i input all of that but cannot assign the values to the target objects transform.position. I have seen SLERP used a lot when i have googled but i can’t get my head around how to make it work and how it actually works with to.positions and from.positions.

Here is my code to calculate the arc points:

void controllerArc()
	//Set the two centre coordinates to be the players Y and Z positions
	//Using only Y and Z to keep the circle in which the object travels in 2 dimensions
	float aCentre = transform.position.y;
	float bCentre = transform.position.z;
	float radius;
	float diameter;
	float xyDistance = 3.0f;
	float PI = Mathf.PI;
	float targetPos;
	//Maths equations going down
	radius = ((xyDistance - aCentre)*(xyDistance - aCentre)) + ((xyDistance - bCentre)*(xyDistance - bCentre));
	radius = Mathf.Sqrt(radius);
	diameter = radius * 2;
	if(Input.GetAxis("360_XButton") > 0.0)
		target.transform.RotateAround (currentPlayer.transform.position, Vector3.left, 100 * Time.deltaTime);

		//target.transform.position = Vector3.Slerp(currentPlayer.transform.position , target.transform.position, xyValue);
		targetPos = diameter * PI * rThumbArc/360;
		//targetPos.z = diameter * PI * rThumbArc/360;
		//target.transform.position = transform.position;

The basic idea is shown in this expertly drawn paint diagram:


Can anyone help me understand how to use SLERP if this is in fact the best way to do it. Otherwise could anyone point me in the right direction in how to solve this :slight_smile:

Thanks guys!

Try this out:

private var Target = Vector3(0, 1, 0);
var Player : Transform;
private var RThumbInput : Vector3;
var OrbitDist : float = 5.0;
var Damping : float = 0.5;

function Update () {
	RThumbInput = Vector3(Input.GetAxis("360_RThumbButton_X"), Input.GetAxis("360_RThumbButton_Y"), 0);
	if(RThumbInput.normalized !={
		Target = RThumbInput.normalized * OrbitDist;
		Target = Target.normalized * OrbitDist;
	transform.position = Vector3.Slerp((transform.position - Player.position), (Target - Player.position), RThumbInput.magnitude * Damping);
	transform.position += Player.position;

I’ve used what I’m guessing are your axis names from your script. I can’t test it very easily as I’ve said as I don’t have a controller but I’m hoping it will do what you want.


  • You need to set the player variable
    transform to either your player or
    something else at the centre of the
    desired rotation.
  • The ‘OrbitDist’ should be set to how
    far away you want the object to be
  • Damping will need small adjustments
    your end to make the rotation smooth
    but not too slow etc.

Good luck, I hope that works for you!


Forgive the simplicity, but if your simply looking to clamp the movement to an arc and use the thumb stick to control the movement of the object along the arc, would the code below suffice?

shield = (GameObject)GameObject.Instantiate(shield, transform.position + shieldDistance, Quaternion.identity);
shield.transform.RotateAround(transform.position, new Vector3(Input.GetAxis("Vertical"), 0, Input.GetAxis("Horizontal")), rotationSpeed * Time.deltaTime);

I think you could use this as a basis from which to build more complex behavior. If this is way off just pretend I never posted this :slight_smile: