- Home /
character turning around.
Right now im using the fpsWalker script and adjusted it to use for a 2.5d type game. I was just wondering if its possible for my character when i hit A to go backwards insted of just going backwards. For my character to 180 and be facing that way and then turn back when D is hit.
Answer by e-bonneville · Jul 06, 2010 at 05:14 PM
Use this:
function Update () {
if (Input.GetButtonDown("Fire1")) {
transform.eulerAngles = Vector3(0,180,0);
}
}
to turn your character around.
Answer by Karl Kujak · Jul 06, 2010 at 08:05 PM
I couldnt get that to work.....here is my code for moving ... where would i put it
//Moving arond var speed = 6.0; var jumpSpeed = 8.0; var gravity = 20.0; //shooting var bullitPrefab:Transform; //dying private var dead = false;
//getting hit //static var gotHit = false;
function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag == "fallout") { dead = true; // sub life here //healthcon.LIVES -=1; } }
private var moveDirection = Vector3.zero; private var grounded : boolean = false;
function FixedUpdate() { if (grounded) { // We are grounded, so recalculate movedirection directly from axes moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed;
if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; } }
// Apply gravity moveDirection.y -= gravity * Time.deltaTime;
// Move the controller var controller : CharacterController = GetComponent(CharacterController); var flags = controller.Move(moveDirection * Time.deltaTime); grounded = (flags & CollisionFlags.CollidedBelow) != 0;
if(Input.GetMouseButtonDown(1)) {
var bullit = Instantiate(bullitPrefab, GameObject.Find
("spawnPoint").transform.position, Quaternion.identity);
bullit.rigidbody.AddForce(transform.right * 3000);
} }
function LateUpdate() { if(dead) { transform.position = Vector3(-55,7,0);
dead = false;
}
}
@script RequireComponent(CharacterController)
Answer by Will 7 · Sep 01, 2010 at 02:44 AM
Just add
if (Input.GetKeyDown (KeyCode.a)) {
var translation = Time.deltaTime * 180;
transform.eulerAngles = Vector3(0,translation,0);
}
into a function update. I think....
Your answer
Follow this Question
Related Questions
Sprite Manager Animation/Walker Brothers Mario 1 Answer
projectile to cursor for a side scrolling shooter 0 Answers
Trying to get character to instantly rotate in 2.5d side scroller 1 Answer
How to make a side scroller dirtbike move across hills. 0 Answers
how to do 2.5D side scroller-Gun point towards mouse then -180 character turn 1 Answer