- Home /
RigidBody properties Not Working.
Rigidbody Properties not working...check out my code and help me get through it. It shows a error line under rigidbody.AddForce
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
void FixedUpdate ()
{
rigidbody.AddForce(15f);
}
}
Answer by TeohRIK · May 23, 2018 at 05:13 AM
You to get your rigidbody component first
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
Rigidbody RB;
void Start(){
RB = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
RB.AddForce(15f);
}
}
Answer by Z-ion · May 23, 2018 at 05:26 AM
Thanks @TeohRIK it is working fine, but in the tutorial they do it without specifying the component,then too it their's working.
Tutorial Link: https://youtu.be/MBDWTjn05eg
That an old tutorial actually, you no need to get the rigidbody component to use rigidbody function in Unity 4 or older. But in Unity 5 or newer version, they change it already, you had to get the rigidybody component to use rigidbody function.
Your answer
![](https://koobas.hobune.stream/wayback/20220612163239im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
AddForce to position on Rigidbody 2 Answers
Confusion with AddForce with ForceMode.Acceleration 1 Answer
How to make rigidbodies on each side of a cube fall towards the cube? [multiple gravity / addForce] 0 Answers
raycast hit add force problem, help needed please 1 Answer
Calculate forces required to rotate around an arbitrary point regardless of center of mass position 1 Answer