Hello Community!
I desperately need your help!
I want to make a Ball-Roll game. I’m a beginner with C# and Unity, but I want to learn! I have found code snippets in the Internet, but I don’t know where to put them, as I am a total newbie…
The Situation is the following:
I want to move a ball in all 4 directions on a plane, let the camera follow it horizontally and let the Ball move “away” from the camera when pressing W.
I am posting my “PlayerControl”-Script later. I can get the ball to move in all 4 directions so far. But the directions are bound to the world coordinates. Means pressing “W” makes the ball go towards the Z-axis, “D” towards the X-Axis and so on.
The problem is, I can’t get the camera to turn with the A and D keys horizontally and add a Force to the ball towards the cameras forward position!
I know asking for code is not the way to learn, but I can’t continue without it!
Is there someone who is able to get me the right code and explain me where to put that?
I hope you can help me!
Here is my playerScript so far…
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
}
-Pirfsich