- Home /
moving object whilst keeping a constant y position
I am making a sprite based top down shooter, and am having a problem with my enemies changing vertical plane when perusing the player.
here is my script for the enemy movement
function lookAt()
{
renderer.material.color = Color.yellow;
var rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}
function chase()
{
renderer.material.color = Color.red;
moveDirection = transform.forward;
moveDirection *= moveSpeed;
controller.Move(moveDirection * Time.deltaTime);
}
how can I make it so the y position stays constant?
thanks
Answer by Bru345 · Apr 28, 2014 at 09:43 PM
var playerRidg = rigidbody.velocity;
playerRidg.y = //enter desired value, where you want the player to remain
rigidbody.velocity = playerRidg;
Answer by 0V3RR1D3 · Apr 28, 2014 at 09:39 PM
I'm not quite sure what you mean, but from what i see , can't you just do transform.position.y = whateverNumberYouWantItToStayAt;
Answer by Vandarthul · Apr 28, 2014 at 09:37 PM
transform.eulerAngles = new Vector3(transform.eulerAngles.x, 0,transform.eulerAngles.z);
Your answer
Follow this Question
Related Questions
Gradual Rotation of Character from 2 Axis Input Sources 0 Answers
Rotate vector around vector? 2 Answers
Move Forward Locally While Still having Collision 1 Answer
Rotating a character's velocity? 3 Answers