Need a 2D Rigid Body Controller Script
So I'm working on a Sonic game, which I just got my sprites and what-not imported, and I'm finally at the moment where I need a script to move the character. No matter what videos I've watched or scripts I've tried writing, nothing seems to work for me.
I'm new at this myself, and here's what I got from a video. Sadly I a few of the characters he used, so I'm not sure if I even typed the right char to end it.
using UnityEngine; using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public float moveSpeed;
public float jumpHieght;
public Rigidbody2D rigidBody2D;
// Use this for initialization
void Start () {
rigidBody2D = GetComponent<rigidBody2D> ();
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown (KeyCode.Space)){
(
GetComponent<Rigidbody2D>().velocity = new Vector2(0. JumpHeight);
}
}
If anyone can help out, so much would be appreciated! :) Thanks in advance!
Answer by Lord_Ford · Aug 23, 2015 at 09:34 PM
Well in you Start function you shouldnt be getting a rigidBody2D but instead a RigidBody2D. Also, you dont have to repeat the process of getting RigidBody2D like you have in your if statement. Just use the holder which is "rigidBody2D".
rigidBody2D.velocity()...
Cheers! -PlayWell Studios
Your answer
Follow this Question
Related Questions
Why is this point light square? 1 Answer
Programming in 2d games 0 Answers
Modular entity construction 0 Answers
What is wrong with this code? 2 Answers