Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (frutza, Quad, AndrewAMD), 385 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: How i can make to a entity turn to face player [Re: JackTheRipper] #105493
01/05/07 19:37
01/05/07 19:37
Joined: Dec 2005
Posts: 252
MyOwnKingdom
nipx Offline
Member
nipx  Offline
Member

Joined: Dec 2005
Posts: 252
MyOwnKingdom
instead of if(key_e==on) place if(key_enter==on)...
If I understood you rigt...



nipx

Re: How i can make to a entity turn to face player [Re: JackTheRipper] #105494
01/05/07 19:43
01/05/07 19:43
Joined: Jan 2006
Posts: 53
L
LWD Offline OP
Junior Member
LWD  Offline OP
Junior Member
L

Joined: Jan 2006
Posts: 53
It works fine, thanks to all! But when i press key_e the entity turns very fast, have a way to change de speed that the entity rotate?
Thanks!

Last edited by LWD; 01/05/07 19:45.
Re: How i can make to a entity turn to face player [Re: LWD] #105495
01/05/07 20:05
01/05/07 20:05
Joined: Dec 2005
Posts: 252
MyOwnKingdom
nipx Offline
Member
nipx  Offline
Member

Joined: Dec 2005
Posts: 252
MyOwnKingdom
With vec_to_angle(my.pan, temp); you set the new angle (pan) directly. If you want to turn it use c_rotate.


--->>

Save the new angle.
Code:

//create new vector to store angles
var vecAngle[3]

-> vec_to_angle(vecAngle, temp);


then calculate the difference between the angle the enemy has now and the one he should turn to.

Code:

//get diff between current angle and the needed
vec_diff(temp, vecAngle, my.pan);



then turn your enemy

Code:

c_rotate(me, temp, glide);




I didnt test it but it should work.



nipx

Re: How i can make to a entity turn to face player [Re: nipx] #105496
01/05/07 20:19
01/05/07 20:19
Joined: Jan 2006
Posts: 53
L
LWD Offline OP
Junior Member
LWD  Offline OP
Junior Member
L

Joined: Jan 2006
Posts: 53
I did not understand...
How i can apply this code to the old code?
I substitute the old code:
vec_set(temp, player.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
for the new:
var vecAngle[3]
vec_diff(temp, vecAngle, my.pan);
c_rotate(me, temp, glide);

and the entity turns to left, and not to the player...
Thanks!

Last edited by LWD; 01/05/07 20:21.
Re: How i can make to a entity turn to face player [Re: LWD] #105497
01/05/07 20:28
01/05/07 20:28
Joined: Dec 2005
Posts: 252
MyOwnKingdom
nipx Offline
Member
nipx  Offline
Member

Joined: Dec 2005
Posts: 252
MyOwnKingdom
Code:

var vecAngle[3];
vec_set(temp, player.x);
vec_sub(temp, my.x);
vec_to_angle(vecAngle, temp);
vec_diff(temp, vecAngle, my.pan);
c_rotate(me, temp, glide);




nipx

Re: How i can make to a entity turn to face player [Re: nipx] #105498
01/05/07 20:44
01/05/07 20:44
Joined: Jan 2006
Posts: 53
L
LWD Offline OP
Junior Member
LWD  Offline OP
Junior Member
L

Joined: Jan 2006
Posts: 53
thanks! this works, but the entity rotate very fast too... How i change the speed of the rotation? Thanks a lot!

Re: How i can make to a entity turn to face player [Re: LWD] #105499
01/05/07 21:06
01/05/07 21:06
Joined: Dec 2005
Posts: 252
MyOwnKingdom
nipx Offline
Member
nipx  Offline
Member

Joined: Dec 2005
Posts: 252
MyOwnKingdom
Code:

var vecAngle[3];
vec_set(temp, player.x);
vec_sub(temp, my.x);
vec_to_angle(vecAngle, temp);
vec_diff(temp, vecAngle, my.pan);

var Scale =0.25;//(play with 0.25...)
var counter=0;
var tmpCounter;

//scale vector, make it slower
vec_scale(temp,Scale);

//calculate how many times to rotate when vector is scaled
tmpCounter= 1 /Scale; //when using 0.25 -> 4


while(counter < tmpCounter)
{
c_rotate(me, temp, glide);
counter+=1;
wait(1);
}




dont know if this will work but I hope


nipx

Re: How i can make to a entity turn to face player [Re: nipx] #105500
01/05/07 21:26
01/05/07 21:26
Joined: Jan 2006
Posts: 53
L
LWD Offline OP
Junior Member
LWD  Offline OP
Junior Member
L

Joined: Jan 2006
Posts: 53
Thanks a lot! I just made a change in the order of the lines of you code and it works fine!
Thanhs to all!!!

Last edited by LWD; 01/05/07 21:43.
Re: How i can make to a entity turn to face player [Re: LWD] #105501
01/05/07 21:44
01/05/07 21:44
Joined: Dec 2005
Posts: 252
MyOwnKingdom
nipx Offline
Member
nipx  Offline
Member

Joined: Dec 2005
Posts: 252
MyOwnKingdom
try this:

Code:


//scale vector, make it slower
vec_scale(temp,(Scale *time_step));

//calculate how many times to rotate when vector is scaled
tmpCounter= Scale *time_step ;

while(counter < tmpCounter)
{
c_rotate(me, temp, glide);
counter+=1;
wait(1);
}





edit: if it works now you still should include time_step in your code otherwise the rotation wont be smooth

Last edited by nipx; 01/05/07 22:03.
Re: How i can make to a entity turn to face player [Re: nipx] #105502
01/06/07 01:08
01/06/07 01:08
Joined: Jan 2006
Posts: 53
L
LWD Offline OP
Junior Member
LWD  Offline OP
Junior Member
L

Joined: Jan 2006
Posts: 53
Thanks! This code work fine too... but the codes that you have posted have just a problem, when i try to walk around the entity, some times he have a "bug", he turns to the wrong side. example: i go to the left of the entity and the entity rotate to right to go for the left... Have a way to fix this bug?
I hope that you have understood me.
Thanks!

Page 2 of 3 1 2 3

Gamestudio download | chip programmers | 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