Question by
Fenix_Prime · Jan 07, 2017 at 05:43 AM ·
c#collisionrigidbody
Rigidbody object colliding with plane.
So I have a plane and a small sphere with a rigidbody attached to it. This is the script that is attached to the player object (the small sphere):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
private float moveSpeed;
private Rigidbody rb;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.W))
{
moveSpeed = 22;
} else
{
moveSpeed = 10;
}
player_movement();
}
private void player_movement()
{
if (Input.GetKey(KeyCode.W))
{
rb.MovePosition(transform.forward + transform.position * moveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S))
{
rb.MovePosition(-transform.right + transform.position * moveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A))
{
rb.MovePosition(-transform.forward + transform.position * moveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.D))
{
rb.MovePosition(transform.right + transform.position * moveSpeed * Time.deltaTime);
}
}
}
Here Is a video of what happens when I try and use any of the WASD keys. It's like the object is stuck to the floor plane. How do I fix this?
Comment
Your answer
Follow this Question
Related Questions
Unity 5: AddForce Increases power when already being pushed towards a collider. How to make stop? 1 Answer
How to Make A Character Stop At Wall? 0 Answers
Why Does A Rigidbody Affect Enemy Health? 1 Answer
how to add rigidbody to my mouseposition 1 Answer
How do you fix a Rigidbody stopping quickly after the addforce stops being called? 1 Answer