1 registered members (TipmyPip),
18,449
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
vec to angle problem
#378478
07/24/11 06:28
07/24/11 06:28
|
Malice
Unregistered
|
Malice
Unregistered
|
I'm using vec to angle to make a lock system like the zelda games. It works fine. But when I circle the target, if I go 180* around him to his back, it bugs out for a split second.The player turns a full 180* and faces away from the target. It last only a slit second and then returns to the expected behavior. Does anyone know how to fix this? Thanks.
|
|
|
Re: vec to angle problem
[Re: 3run]
#378482
07/24/11 06:48
07/24/11 06:48
|
Malice
Unregistered
|
Malice
Unregistered
|
Here you go almost straight out the manual.
if(!mov_targetlock)
{
mov_rotdir.pan = -mouse_force.x;
}
else
{
vec_set(vectemp,det_last_target.x);
vec_sub(vectemp,my.x);
vec_to_angle(my.pan,vector(vectemp.x,vectemp.y,0));
}
|
|
|
Re: vec to angle problem
[Re: ]
#378483
07/24/11 06:54
07/24/11 06:54
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
USE this:
ANGLE temp_ang;
......
vec_set(vectemp,det_last_target.x);
vec_sub(vectemp,my.x);
vec_to_angle(temp_ang.pan,vectemp.x);
my.pan += sign(ang(temp_ang.pan - my.pan)) * time_step * 5; // 5 is turning speed
This will make turning a lot smoother, may be this will fix the problem, try.
|
|
|
Re: vec to angle problem
[Re: 3run]
#378485
07/24/11 07:04
07/24/11 07:04
|
Malice
Unregistered
|
Malice
Unregistered
|
3run... The code you posted fixes my problem but starts a new one. Now when the player is locked on but not moving the screen shakes left and right.If I start moving the shaking stops but starts again when I stop. Any Ideas?
|
|
|
Re: vec to angle problem
[Re: ]
#378487
07/24/11 07:12
07/24/11 07:12
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
Script I've posted has nothing to do with screen. ^^ It just turns "temp_ang" to target and then smoothly make's player's pan turn to "temp_ang". Please, check your script, may be you using "temp_ang" somewhere? Or something like that. Check where else you are using:
det_last_target.x
vectemp
temp_ang
my.pan
Other ways, I have no idea. Something must be wrong with your script, or with way you use the one I've posted.
|
|
|
Re: vec to angle problem
[Re: 3run]
#378504
07/24/11 13:08
07/24/11 13:08
|
Joined: Feb 2011
Posts: 135
Myrkling
Member
|
Member
Joined: Feb 2011
Posts: 135
|
This line can make the camera shake, especially if time_step has a large value: my.pan += sign(ang(temp_ang.pan - my.pan)) * time_step * 5;Replace it with something like this to make the rotation stop accurately: var pan_diff = ang(temp_ang.pan - my.pan); my.pan += sign(pan_diff) * minv(abs(pan_diff), time_step * 5);To make the rotation smoother you need a few more lines of code:
var pan_diff = ang(temp_ang.pan - my.pan);
// Replace 10 (in both lines) with a higher value to make the rotation stop more smoothly.
if (abs(pan_diff) < 10)
my.pan += abs(pan_diff)/10 * sign(pan_diff) * time_step * 5;
else
my.pan += sign(pan_diff) * minv(abs(pan_diff), time_step * 5);
This should work better. At least I think so. 
|
|
|
Re: vec to angle problem
[Re: Myrkling]
#378507
07/24/11 13:22
07/24/11 13:22
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
This line can make the camera shake, especially if time_step has a large value: my.pan += sign(ang(temp_ang.pan - my.pan)) * time_step * 5; If "time_step" has a larger value? Could you explain please, how could that be? ^^ How could time_step has larger value? And please, be so kind to explain, what "my.pan" has to do with camera's side-to-side shaking? And with camera itself?
|
|
|
Re: vec to angle problem
[Re: Myrkling]
#378525
07/24/11 15:35
07/24/11 15:35
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
I see what you mean now, you didn't ment "time_step" itself, but only result which it gives by 5. You are right with that one. But he didn't say that camera's angle depends on the entities one. Also, he didn't face any shakes on player's turning  Only camera.
|
|
|
|