- Home /
Question by
atiquec · Mar 13, 2017 at 08:10 PM ·
rigidbody2d
Rigidbody2d NPC movement
Hello scripting noob here,
I am trying to make a flying npc that always refers to my Camera and move slightly left and right in a timely manner.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour {
// Movement speed
public float speed = 2;
public float force = 300;
public Transform target;
private Rigidbody2D rb2d;
// Use this for initialization
void Start () {
// Fly towards the right
//GetComponent<Rigidbody2D>().velocity = Vector2.right * speed;
rb2d = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void FixedUpdate () {
GetComponent<Rigidbody2D>().velocity = Vector2.right * speed;
}
}
Is there a way to target the camera while moving left and right with this character?
Comment