Rigidbody.MovePosition doesn't work on selective objects.
So I have a character model with a lot of children (Being arms, fingers, etc.) FBX import,
I have the following script attached to it:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class TestRigidbody : MonoBehaviour
{
Rigidbody rb;
Vector3 position;
float runningSpeed;
Vector3 playerMovement;
// Use this for initialization
void Start()
{
rb = this.GetComponent<Rigidbody>();
runningSpeed = 2f;
}
// Update is called once per frame
void FixedUpdate()
{
playerMovement = new Vector3(0f, 0f, 0.05f);
rb.MovePosition(this.transform.position + playerMovement.normalized * runningSpeed * Time.deltaTime);
}
}
For some reason the character is stuck in it's position, despite the fact that in Debug.Logs, you see that the result of the parameter in MovePosition(param) produces a changing result. Adding this exact script to another object, like a simple cube Does make the cube move. Interestingly enough, transform.Translate() does work on BOTH the cube and the character model. However I need the physics system for what I am trying to do.
Does anybody know wow it is possible that the exact script works for 1 object but doesn't work on another object, when working with Rigidbody.MovePosition(), where as moving that object would work for both when working with transform.Translate()?
Answer by Lushlush · Nov 25, 2019 at 10:46 AM
This problem was solved by removing the CharacterController component from the character object.
Answer by goutham12 · Nov 25, 2019 at 10:05 AM
there might be few problems in your case. 1) may be your charcter doesn't have rigidbody. 2) Mass : if rigidbody exists may be the mass is higher so the force you are applying is not enough to move. 3) drag : check in your rigidbody properties what's the drag you are using. by default it is zero. 4) Constrains: check this portion alson in the inspector.
Actually you can reset the rigid body property.
The
[RequireComponent(typeof(Rigidbody))]
Includes a rigid body with standard values. $$anonymous$$ine are: $$anonymous$$ass = 10, Drag = 0, angular drag = 0.05, Use gravity = true, Is$$anonymous$$inematic (tried both true and false)), Interpolation = None, Col Detection = Continues/Discrete (tried both), Constraints = (No constraints and restrain Freeze X & Z rotation, tried both).
$$anonymous$$y character model is about the same size as the standard cube, twice the height but thin. Although it has many children (50+).
It also has an animator and Character controller attached, though copying those over to the cube didn't prevent the cube from working with $$anonymous$$ovePosition()
Gravity does work on my character as disabling the collider results in the character falling through the level, yet it refuses to work with the Rigidbody.
Your answer
Follow this Question
Related Questions
rigidbody.MovePosition to rigidbody.velocity 0 Answers
Moving RigidBody Smoothly 0 Answers
Moving a cube with RigidBody. MovePostition, it randomly stops moving 0 Answers
Control speed of a rigidbody that move to a fixed distance 2 Answers
How to: rigidbody.MovePosition to player's position 2 Answers