- Home /
My dash looks like a teleport
So i'm making a dash in a spinning top game, it moves in the direction i want it to and at the speed i want it to but instead of looking like a dash it looks more like a teleport Here's the code I made ;
using UnityEngine;
using System.Collections;
public class Dash2 : MonoBehaviour {
public float speed = 10.0f ;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.X)) {
var move = new Vector3 (Input.GetAxis ("Vertical"), 0, Input.GetAxis ("Horizontal"));
rigidbody.AddForce(transform.position += move * Time.deltaTime * speed );
rigidbody.useGravity = true ;
}
}
}
Answer by AlwaysSunny · Nov 25, 2014 at 07:15 PM
Your AddForce method arguments make no sense. Either add to the position or add a force.
First, you probably want this before doing anything with the move variable
move = Vector3.ClampMagnitude(move,1);
Then, add force like so.
rigidbody.AddForce( move * force );
Note that adding a constant force (as you're doing) in Update() is a bad idea. As a general rule, all input gathering goes in Update(), and all physics interactions belong in FixedUpdate().
sorry it took me so long to see this but i put in what you suggested and the move keeps co$$anonymous$$g up red
Your answer
Follow this Question
Related Questions
Double tap to dash (With Multiple keypress) 0 Answers
Going insane from this 1 Answer
Dash and player script not working together! 0 Answers
Unity 2D -- Dash instantly stops 1 Answer
How to do a "dash"-movement, set distance on key-input? 0 Answers