I would like to make a plane (not an airplane) the plane you would use for your floor move up and down with the arrow keys along the X and Z axis. I’m new at c# and would like to find out what things I would need to incorporate into the script I figure some type of Vector3 and something to do with rotation and something to give it a maximum height angle and minimum depth angle but I’m not sure what type of scripts to look for in order to do that. I also tried making the plane a rigidbody. But it didn’t like that either.
Such a script is not complex:
using UnityEngine;
public class Mover : MonoBehaviour {
public Vector3 velocity = Vector3.up;
void Update() {
if (Input.KeyDown(KeyCode.Up)) transform.position += velocity * Time.deltaTime;
if (Input.KeyDown(KeyCode.Down)) transform.position -= velocity * Time.deltaTime;
}
}
…but of course if you don’t know C# syntax, or the Unity API, then yes, this would be hard to write. I recommend going through the tutorials in the Learn section, and pay special attention to the ones that show scripting. If you’re new to C#, also spend the time to go through everything at http://learncs.org too. Then you’ll have a foundation to start making things like this yourself.
Also, if any of the above code doesn’t make sense to you, just ask! We’re happy to help.
Thanks Joe I’ve done the roll a ball and the first shooter tutorial and I can understand the code. I just don’t yet understand what code to do for what things to do.
I am also new to Unity scripting.
Try Tanks! tutorial, it gave me a good understanding of different challenges with scripts.
You can also using some visual editing asset extension to ease that.
I have found this asset (Game Rules) which has remade this Tanks tutorial without opening a single time Mono. It is quite awesome.
Actually this script that I found is the script that I wanted.
public Vector3 velocity = Vector3.up;
public float smooth = 2.0F;
public float tiltAngle = 3.0F;
void Update()
{
float tiltAroundZ = Input.GetAxis(“Horizontal”) * tiltAngle;
float tiltAroundX = Input.GetAxis(“Vertical”) * tiltAngle;
Quaternion target = Quaternion.Euler(tiltAroundX, 0, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime);