hi iam new to unity… here i have created one plane and one sphere, now i need a situation like if i click the play button then the ball should randomly move on the plane… can anybody write the c# for this , thanks in advance
Would AddForce make it? Like if you gave it a push in one direction?
Here is a sample code from the scripting reference:
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
public float thrust;
public Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
rb.AddForce(transform.forward * thrust);
}
}
The transform.forward would need to be randomized as per your description
tqq for the response…
i have created 2 objects (object1,object2) and i made a random moment for one object … if the object touches to another object its going(penetrating) inside the object … but i want like if the object touches to another object it should only change the way of direction not like go inside to another object … may i know which components should we add and also need c# code for this .thanks for advance