- Home /
Why does the spindash not launch off to a far distance?
I am making a Sonic-like 2D game and I am trying to get the spindash to work. It seems to charge correctly, but it is as if the way the force is applied doesn't allow the dash to launch off far. When running the game, I will charge the spindash and when I release it for it to shoot off, it barely moves. There is also an issue of it teleporting when its released and it dashes. For some reason, this problem only occurs in the X-direction. I am just testing it with a simple square because I have not added developed any original sprites yet. If anyone could help that would be great.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ModPlayerController : MonoBehaviour
{
public int speed = 10;
public int jumpForce = 500;
Rigidbody2D rigidBody;
Animator animator;
public TextMeshProUGUI actionText;
//int bulletForce = 100;
public LayerMask groundLayer;
public Transform feetTrans; //empty gameObject
bool grounded = false;
float groundCheckDist = 0.3f;
//public GameObject bulletPrefab;
[SerializeField]private float stickForce;
[SerializeField]private float spinDashSpeed;
[SerializeField] private float minSpinDashTime;
[SerializeField]private float springLaunchVelocity;
private bool flipped;
private bool underWater;
private bool spinDashing;
private float spinDashTimer;
void Start()
{
rigidBody = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
}
private void FixedUpdate()
{
grounded = Physics2D.OverlapCircle(feetTrans.position, groundCheckDist, groundLayer);
//animator.SetBool("Grounded", grounded);
}
// Update is called once per frame
void Update()
{
float xSpeed = Input.GetAxis("Horizontal") * speed;
rigidBody.velocity = new Vector2(xSpeed, rigidBody.velocity.y);
//animator.SetFloat("Speed", Mathf.Abs(xSpeed));
if(grounded && Input.GetButtonDown("Jump"))
{
rigidBody.AddForce(new Vector2(0, jumpForce));
}
if(xSpeed > 0 && transform.localScale.x < 0 || xSpeed < 0 && transform.localScale.x > 0)
{
transform.localScale *= new Vector2(-1, 1); //flip the sprite
//flipped = true;
}
// else { flipped = false; }
//Spindash Controls
//Charge
if(Input.GetKey(KeyCode.DownArrow))
{
spinDashing = true;
spinDashTimer += Time.deltaTime;
actionText.text = "Action: Charging SpinDash!";
}
else if (Input.GetKeyUp(KeyCode.DownArrow) || !grounded)
{
spinDashing = false;
if (spinDashTimer >= minSpinDashTime)
{
rigidbody.AddForce(transform.right *spinDashSpeed)
actionText.text = "Action: Spindash!";
}
spinDashTimer = 0;
}
}
Your answer
Follow this Question
Related Questions
How to make my bullets spread when fired 3 Answers
rolling ball movement on different axis 0 Answers
Trajectory problem with addforce coordinates 1 Answer
AddForce at Local ?? 2 Answers