Alright all i need to do simply is when i press forward the ball, which is the character rotates
Rotates like rolling
Apply a force to it in the direction you want it to roll
will that work if i want it to rotate in a specific direction
click on the sphere in the hierarcy,
go to components in the menu,
go to physics,
click on rigidbody.
This will add stuff like mass and gravity.
I would give you a code, but whats the spirit in that?
Alright I got a movement script but it interferes with my rigid body, for example it randomly rotates when i move and stuff.
The script I used was:
And I know it has a Shooting Function
var speed = 3.0;
var rotateSpeed = 3.0;
var bullitPrefab:Transform;
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis (“Horizontal”) * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis(“Vertical”);
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown(“Jump”))
{
var bullit = Instantiate(bullitPrefab,
GameObject.Find(“spawnPoint”).transform.position,
Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 200);
}
}
@script RequireComponent(CharacterController)
can’t anyone help me?
Try using rigidbody.AddForce and AddTorque instead of Move* functions of the transform.
You generally shouldn’t directly manipulate rigidbodies using Transform
thank you, i will do
Hehe, that is exactly what I told you to do, apply a force in the direction you want to move ![]()
Alright i have Transform.AddFrce but it doesnt work, i am really noob at java script and could really use your help
rigidbody.AddForce(vector3.left * 20);
does that work?
My new Script is:
var speed = 3.0;
var rotateSpeed = 3.0;
var bullitPrefab:Transform;
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis (“Horizontal”) * rotateSpeed, 0);
var forward = rigidbody.AddForce(Vector3.left *20);
var curSpeed = speed * Input.GetAxis(“Vertical”);
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown(“Jump”))
{
var bullit = Instantiate(bullitPrefab,
GameObject.Find(“spawnPoint”).transform.position,
Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 200);
}
}
@script RequireComponent(CharacterController)
It says
A: Cannot xonvert void to void
B: Operator * cannot be used with a left void and a right hand side of type float
Can someone please help me, i just want to know how to make this work!
This worked for me a while ago
var speed = 10.0;
var gravitypull = 0;
function FixedUpdate() {
rigidbody.AddForce (Vector3(0, gravitypull, 0));
var cameraTransform = Camera.main.transform;
// Forward vector relative to the camera along the x-z plane
var forward = cameraTransform.TransformDirection(Vector3.forward);
forward.y = 0;
forward = forward.normalized;
// Right vector relative to the camera
// Always orthogonal to the forward vector
var right = Vector3(forward.z, 0, -forward.x);
if (Input.GetKey ("w")) {
rigidbody.AddForce(forward * speed * Time.deltaTime);
}
if (Input.GetKey("s")) {
rigidbody.AddForce(forward * -speed * Time.deltaTime);
}
if (Input.GetKey ("d")) {
rigidbody.AddForce(right * speed * Time.deltaTime);
}
if (Input.GetKey ("a")) {
rigidbody.AddForce(right * -speed * Time.deltaTime);
}
}
Maybe this will help…?