- Home /
vector3 current postion +1
hi i am nooba t this to start! anyways i am making a pong game to practice my scripting and i want it so that when player presses up the object to move up on the y axis +1. so i had this:
using UnityEngine; using System.Collections;
public class bat_right : MonoBehaviour {
public float bat_rightSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
float amntToMove = Input.GetAxis("bat_right") * bat_rightSpeed * Time.deltaTime;
transform.position = new Vector3(
}
}
i want it to not change x and z but to take current y postion and add one unit. is this possible and how would i do it?
thanks in advance
Answer by ckfinite · Jun 05, 2011 at 09:18 PM
Try
float amntToMove = Input.GetAxis("bat_right") * bat_rightSpeed * Time.deltaTime;
transform.position += Vector3.up * amntToMove;
perfect thank you but the bat keeps moving when i let go of the button. why is it doing that may i ask?
Try wrapping the statement in
if ($$anonymous$$athf.Abs(Input.GetAxis("bat_right")) > .05 /* Threshold value */)
{
//code here
}
fixed my last problem i turned up the gravity in the input panel in unity
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Help to figure a logic to achieve a movement. 2 Answers
object reflecting of a wall 1 Answer
Problems Scripting a Camera 1 Answer
Unable to fully rotate GameObject on tap 2 Answers