- Home /
Circular Platform
I am attempting to create a side scrolling 2.5 plat former, but instead of straight platforms, I'm thinking about creating one continuous plat former, or one that loops. How do I keep the character grounded so it won't fall off this circular platform?
Here's the script I have on my character as of now.
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
moveDirection = Vector3(0,0,Input.GetAxis("Horizontal"));
moveDirection *= speed;
if (moveDirection.sqrMagnitude > 0.01)
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (moveDirection), 1);
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -=gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
Answer by gregzo · Sep 30, 2012 at 09:07 AM
If I understand you well, you want your level to be a circular strip? Seen from above : o ? Player moving clockwise or counter clockwise?
If that's the case, you could make the player object a child of an empty object which is centered at the center of the circle.
When you want the player to move along the y axis, move it's parent instead.
When you want the player to move horizontaly, rotate his parent instead.
Does it help?
Yes, correct. I guess gravity would be the correct problem of this then. Basically the platform is a cylinder turned on its side, so all the player would see is a circle with the player on top. Here's a link that basically sums up what I'm thinking about, besides the 2 other platform.
http://www.youtube.com/watch?v=qz8mFZczu$$anonymous$$0
Thanks for the answer.
Answer by Bindlestick · Sep 30, 2012 at 10:49 PM
Thanks. For your recent advice, I've been having partial luck. The character is facing the center of the circle, but I'm having trouble having his bottom facing the center. I guess that can be fixed by messing with the x, y and z of one of the coding I've added. I'm also having trouble with the transformDirection code, the "Object reference not set to an instance of an object" error.
var characterlook : Transform = target.transform;
var charRelativeRight : Vector3 = characterlook.TransformDirection (Vector3.right);
rigidbody.AddForce (charRelativeRight * 10);
var target : Transform;
function Update () {
// Rotate the camera every frame so it keeps looking at the target
transform.LookAt(target);
}
Your answer