- Home /
Super Sonic Movement Help
I'm trying to recreate the sonic boss fight from the game "I wanna be the boshy" just for fun and currently I'm at the stage where I'm programming super sonic and trying to program this attack: https://www.youtube.com/watch?v=h_o8AnZX9FA&feature=youtu.be&t=18s
I'm using this function that is run in the Update loop for the attack:
public void SuperFly(float speed, float maxSpeed)
{
float xa = speed;
float ya = speed;
flyV = rig.velocity;
xv = Mathf.Clamp(xv, -maxSpeed, maxSpeed);
yv = Mathf.Clamp(yv, -maxSpeed, maxSpeed);
flyV.x = xv;
flyV.y = yv;
rig.velocity = flyV;
Vector2 v = rig.velocity;
float angle = Mathf.Atan2(v.y, v.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
transform.localScale = new Vector3(1, 1, 1);
if(!runningState) //Start Of State
{
stateTimer = 30f;
anim.SetTrigger("SuperFly");
transform.position = deathPoint.transform.position;
runningState = true;
}
if (transform.position.x > player.transform.position.x)
{
xv -= xa;
}
else
{
xv += xa;
}
if (transform.position.y > player.transform.position.y)
{
yv -= ya;
}
else
{
yv += ya;
}
}
It seems to be very similar to the movement in the game but there is just something about it that is off and I can't tell what. It seems sonic's movements in the actual game is a lot more quick and sharp then mine are but I'm not sure how I can edit my code to make that happen. This is what the movement looks like within my game: http://i.imgur.com/742KsgR.gif
If you look at the video and my gif then you should be able to see a difference with the movement but as I said, I'm just unsure what to change. I'd love some help
Answer by lamphung719 · Dec 27, 2016 at 06:39 AM
maybe this can help you out?
https://s-media-cache-ak0.pinimg.com/originals/6c/1b/a4/6c1ba40bf194cd0fc99c06207246b51f.gif
You need a little bit math for this, from the motion type, you need an equation to deter$$anonymous$$e parameters for your movement. This site maybe helps you a bit to generate the equation http://www.timotheegroleau.com/Flash/experiments/easing_function_generator.htm
Don't think I'm actually skilled enough to do that, sadly.
You can also use a package that already implements all type of interpolation functions. Have a look DOTween, it's a great package for tweening (doing animation based on interpolation).
hey man, did you set up your DOTween in the editor?