Rigidbody doesn't work with my script
Hello, sorry if my English isn't good because I'm French.
I did a script for my player (a sphere) which I can control it by using a joystick. When I put my script in my sphere, everything works perfectly. Then I add a rigidbody as a component to my sphere for the gravity. But the problem is that my sphere doesn't want to fall, and this one is turning around itself quickly... I don't know why...
My script is following :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMotor : BaseMotor
{
public VirtualJoystick joystick;
protected override void UpdateMotor()
{
// Get the input
MoveVector = InputDirection();
// Send the input to a filler
MoveVector = state.ProcessMotion(MoveVector);
// Move
Move();
}
private Vector3 InputDirection()
{
Vector3 dir = Vector3.zero;
// dir.x = Input.GetAxis ("Horizontal");
// dir.z = Input.GetAxis ("Vertical");
dir.x = joystick.Horizontal();
dir.z = joystick.Vertical();
if (dir.magnitude > 1)
dir.Normalize();
return dir;
}
}
When I uncheck "script" in my sphere, everything works.
Thank you !
Hello, thank you for answering ! You see ? Everything in my Rigidbodt is O$$anonymous$$. That's my WalkingState script for the sphere's movement :
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class WalkingState : BaseState { public override Vector3 Process$$anonymous$$otion (Vector3 input) { return input * motor.Speed; } }
No I succeeded to fix it ! In "constraints", check Z in rotation ! But it still doesn't fall.
Your answer
Follow this Question
Related Questions
After added a rigidbody in a GameObject, it moves on rotation 2 Answers
Is it possible to change gravity for only one object? 1 Answer
How can I turn a sphere with the mouse while using normal controls to move it? 0 Answers
Rigidbody player movement doesn't response to gravity 0 Answers
let rigidbody idle around in space 1 Answer