Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,388 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
vec to angle problem #378478
07/24/11 06:28
07/24/11 06:28

M
Malice
Unregistered
Malice
Unregistered
M



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: ] #378479
07/24/11 06:40
07/24/11 06:40
Joined: May 2009
Posts: 5,377
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
Could you post script of how you make player turn to target?


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: vec to angle problem [Re: 3run] #378482
07/24/11 06:48
07/24/11 06:48

M
Malice
Unregistered
Malice
Unregistered
M



Here you go almost straight out the manual.

Code:
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 Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
USE this:
Code:
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.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: vec to angle problem [Re: 3run] #378485
07/24/11 07:04
07/24/11 07:04

M
Malice
Unregistered
Malice
Unregistered
M



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 Offline
Senior Expert
3run  Offline
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:
Code:
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.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: vec to angle problem [Re: 3run] #378504
07/24/11 13:08
07/24/11 13:08
Joined: Feb 2011
Posts: 135
Myrkling Offline
Member
Myrkling  Offline
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:
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. laugh

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 Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
Originally Posted By: Myrkling
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?


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: vec to angle problem [Re: 3run] #378513
07/24/11 14:35
07/24/11 14:35
Joined: Feb 2011
Posts: 135
Myrkling Offline
Member
Myrkling  Offline
Member

Joined: Feb 2011
Posts: 135
If "time_step * 5" is larger than the absolute difference between "temp_ang.pan" and "my.pan", the rotation will overshoot the target angle and cause the entity's pan to shake left and right repetitively (as the target angle is never reached).

If the camera angle depends on the entity's angle (this is what I assumed) the camera will shake, too. laugh

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 Offline
Senior Expert
3run  Offline
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 tongue Only camera.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1