Question by
simonJN · Oct 25, 2021 at 05:59 AM ·
programmingtutorials
Lesson 4.1 - Move in direction of focal point
I am currently doing the Junior programming course. In Lesson 4.1 the ball doesn't seem to be following the direction of the camera when I rotate it. I have checked that my GameObject has the same spelling etc:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerController : MonoBehaviour { public float speed = 5.0f; private Rigidbody playerRb; private GameObject focalPoint;
// Start is called before the first frame update
void Start()
{
playerRb = GetComponent<Rigidbody>();
focalPoint = GameObject.Find("Focal Point");
}
// Update is called once per frame
void Update()
{
float forwardInput = Input.GetAxis("Vertical");
playerRb.AddForce(focalPoint.transform.forward * speed * forwardInput);
}
}
image1.png
(170.2 kB)
Comment
Your answer
Follow this Question
Related Questions
How to start and what to learn? 1 Answer
Getting average value of slider while playing. 0 Answers
I have some problems with my animation.help PLEASE! 0 Answers
Android detection not detected by android phone 0 Answers
Trouble Navigating Pause Menu.... 0 Answers