- Home /
Devil May Cry style Lock-on Movement?
Hi,
I'm wondering if anyone can assist me with a problem I am having.
Basically I have my player pivot around an object with a Static Camera.
I need to adjust my controls depending upon the position of my player in relation to the Object.
If this isn't clear enough I will try to explain further.
Many Thanks
Answer by Dunny · Feb 14, 2013 at 12:46 PM
I should point out the Character is fixed, I just want a rotation for the Player much like a lock-on in Devil May Cry or a Boxing Game.
Thanks
Answer by robertbu · Feb 14, 2013 at 12:44 PM
If the structure is a clean as you make it here, you can figure out the angle of player with respect to pivot/object using Mathf.Atan2(). Something like (untested);
Vector3 v3Pos = player.transform.position - pivot.transform.position.
float angle = Mathf.Atan2(v3Pos.y, v3Pos.x);
if (angle < 0.0f) angle += 360.0f;
With the angle, you can code your behaviors however you want based on the quadrants you specified above.
I'm confused about the problem you are trying to solve. I've not played "Devil $$anonymous$$y Cry," and watching a trailer video on YouTube did not help. I'm guessing at what you want. Any game object will have a transform.forward, transform.up, and a transform.right. The left, down, and back will be the negative of these values. If your joystick uses these vectors for movement, then the joystick will always move the character with respect to his space (i.e. up with the joystick will always move the character forward no matter which way he is facing). You can also use local coordinates for these movements and accomplish the same thing.
As for locking on, take a look at Transform.LookAt() or Quaternion.SetLookRotation().
If I've missed what you are asking, pointing to a specific video at a specific time would be helpful.
Thanks for the help.
Basically I'm still stuck and have decided to just calculate the angle my character has rotated around the object but this is giving me an angle of 0-180 on each side of the Character as apposed to a 360 degree value.
Can anyone shed any light on this problem?
$$anonymous$$any Thanks
Atan2() as I've outlined above will give a signed angle. I believe it returns -180 to 180 which is why I added the "angle + 360.0" above. This is not relative to the character, but as a clock rotation. If you are looking straight down, you will want to use x,z rather than the x,y I used above.
Here is a text script. Drag your Pivot game object on to goPivot then hit the 'A' key to report the angle. This is looking down, so the Atan2 call use 'Z' rather than 'Y'.
public class PivotAngle : $$anonymous$$onoBehaviour {
public GameObject goPivot;
void Update () {
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.A)) {
Vector3 v3T = transform.position - goPivot.transform.position;
float angle = $$anonymous$$athf.Atan2 (v3T.z, v3T.x) * $$anonymous$$athf.Rad2Deg;
Debug.Log ("Angle = "+angle);
}
}
}
Angle are counter clockwise (right hand rotation).
$$anonymous$$any thanks for all the help, I ended up going with,
angle = transform.eulerAngles.y;
that seemed to do the trick.
Your answer
Follow this Question
Related Questions
Rotating Cuboid Around Pivot 2 Answers
A node in a childnode? 1 Answer
Authoritative Networking 2D Movement 0 Answers
Why does the player keep pointing in a specific direction after moving? 0 Answers
Constrain axis of isometric camera ("vertical" only) 0 Answers