private Rigidbody rb;
rb = GetComponent();
rb.AddForce ()
it doesn’t work
i will show you the entire code here
private Rigidbody rb;
rb = GetComponent();
rb.AddForce ()
it doesn’t work
i will show you the entire code here
That’s not how RigidBody.AddForce works.
It seems you’re intention is of moving with a constant speed, you don’t really need a rigidbody.
Try
Vector3 addPos = new Vector3();
addPos.x = inputX * movespeed * Time.deltaTime;
addPos.y = 0;
addPos.z = inputZ * movespeed * Time.deltaTime;
transform.position += addPos;
Your first code:
using UnityEngine;
using System.Collections;
public class player : MonoBehaviour {
public float movespeed;
private Rigidbody rb;
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float inputX = Input.GetAxis("Horizontal");
float inputZ = Input.GetAxis("Vertical");
float moveX = inputX * movespeed *Time.deltaTime;
float moveZ = inputZ * movespeed *Time.deltaTime;
print(moveX + moveZ);
rb.AddForce(moveX, 0f, moveZ);
}
}
@PleaseGiveMeFreeThingsTy is flawless. I’ve already checked.
Create capsule. Add rigidbody. Open constraints, freeze rotations in all axes, for tests probably also position in Y-axis. Set collision detection to continuous dynamic. Add Your script. Set move speed to 200.
Make sure You have in:
Edit → Project Settings → Input, declared axis “Horizontal” and “Vertical”.
You must have missed something in Your setting it up. Check also what is displayed in console, maybe something other modify Your speed and is always printed 0?