Friday, February 7, 2020

unity - Move ball based on direction of force?


I'm trying to make a ball that will move in the direction I push it from, and later pull it to me based on where the player is standing.



using UnityEngine;
using System.Collections;

public class BallForce : MonoBehaviour {

public float thrust;
public Rigidbody rb;

// Use this for initialization
void Start () {

rb = GetComponent ();
}

// Update is called once per frame
void Update () {

if (Input.GetMouseButton (0))
rb.AddForce (transform.forward * thrust);
}
}


This seems to work, but I'm not sure how I get it to move based on the position of the player. How would I do this?




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...