Skip to main content
GameDev.net gamedev.net
🔒 Locked

angle stuff

Started by Muzlack Apr 16, 2002 at 2:11 PM 5 replies 1k views
Original Post
Muzlack
Muzlack
ego.deltax=x2-x1; ego.deltay=y2-y1; float degree = atan2(ego.deltax,ego.deltay); xinc=(float)cosf(degree*3.14/180); yinc=(float)sinf(degree*3.14/180); xinc*=4; yinc*=4; I got this code from another thread. I want the character to move in a *smooth* line towards the point where the player clicked. I did a bunch of bressenham stuff, but when the character is supposed to be moving 4 pixels at a time, it gets bumpy. So I''ve been doing a lot of looking around, and this is what I have come up with. The character only seems to move if you clicked to the upper right. I know that some of my previous posts have made you guys a little irritated because I have been asking really stupid questions, but I''d really like this to look good. Any help? Muzlack Oofmay
--Muzlack
Jesper T
Jesper T
Does this character have a previous speed and/or direction that it should be considered?
Is it only the speed that should be smoothed out or should the direction also be smoothed out (ie make the character move in a curve) ?




(There is no border around this image)
Muzlack
Muzlack
No. He is standing still.
--Muzlack
Muzlack
Muzlack
Oh, and no one seems to understand why, but I am using bressenham lines to move the character from point a to point b. but see, when error overflows, I don''t have a yinc of 1! thats too slow for my character. I have a yinc of 4 and I can''t speed up the frames and slow down the yinc. So I decided I''d use degrees to move the character in that direction. I''d also like to use vectors but I don''t have a clue of where I should start. A link to a tutorial for either subject would be nice. Thanks
--Muzlack
Muzlack
Muzlack
int deltax=ego.deltax;
int deltay=ego.deltay;
double d=sqrt(deltax*deltax+deltay*deltay);
deltax/=d;
deltay/=d;
xinc=deltax*4;
yinc=deltay*4;
This is my code. ego.deltax=x2-x1. ego.deltay=y2-y1
the character does not move at all.
--Muzlack
Jesper T
Jesper T
I think you got some rounding errors there, use float or double instead of int.

A way to make the movement smooth between A and B:


  
Start coordinate:
A = {Ax, Ay}

End coordinate:
B = {Bx, By}

Smoothness value:
s (not a vector)

Points between A and B:
a = A + ((B-A)/s)
b = B - a

A value that decides how far the character has moved:
t
(t is not a vector either, t = 0.5 mean that the character is halfways from A to B)

Character postion:
P = {Px, Py}

For each value of ''t'', you can now calculate a postion (P) like this:

P = A(1-t)³ + 3at(1-t)² + 3b(1-t)t² + Bt³



Its untested, but I''m pretty sure it works.





(There is no border around this image)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.