Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Roll-A-Ball: AddForce into cameras forward direction. How?

$
0
0
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

Viewing all articles
Browse latest Browse all 1264


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>