Question by
Vekosava · Dec 05, 2015 at 07:05 PM ·
charactercharacter movementspread
Why my character spread when moving?
When I move my character, it spread like you see on pictures.
Here is RigidBody and Box Collider picture: http://prntscr.com/9apfl3
Script:
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
public float speed = 8.0f;
public float maxVelocity = 3.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
GetComponent<Rigidbody2D>();
float force = 0.0f;
float velocity = Mathf.Abs (GetComponent<Rigidbody2D>().velocity.x);
float h = Input.GetAxis ("Horizontal");
if(h > 0) {
if(velocity < maxVelocity)
force = speed;
Vector3 scale = transform.localScale;
scale.x = 1;
transform.localScale = scale;
} else if(h < 0) {
if(velocity < maxVelocity)
force = -speed;
Vector3 scale = transform.localScale;
scale.x = -1;
transform.localScale = scale;
}
GetComponent<Rigidbody2D>().AddForce (new Vector2 (force, 0));
}
}
Can someone tell me where is a problem here?
Thanks.
screenshot-8.jpg
(22.1 kB)
screenshot-9.jpg
(34.0 kB)
Comment
Your answer
Follow this Question
Related Questions
Character object is unstable and I can't figure out why or how to fix it 0 Answers
How to set a start_walking animation using blentree 2 Answers
Help for my character Rotation When using Joystick 0 Answers
How do i move my character in a direction that is not based on the character facing direction? 0 Answers