Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Wizzrobe  (Read 2469 times)

0 Members and 1 Guest are viewing this topic.
Wizzrobe
« on: November 12, 2011, 03:24:39 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 262
I'm almost done with the creation of the wizzrobe enemie for TLOZ:CR.
It can now appear, disappear, move to a different location, attack.



The only thing that is not in it yet is to check which direction it should face ( 0 (or 360 )-90-180-270 )
I want it to check where link is like in the shot below.
Depending on which sector link is in, the direction would be set.
anyone got a clue how to do this?

Logged
Re: Wizzrobe
« Reply #1 on: November 12, 2011, 04:06:46 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Off hand, I believe you should be able to do something along these lines (Pusedo Code).

Code: [Select]
// Work out angle between enemy and link.
// 0 degrees is assumed to be straight up in this example.
angle = atan2(enemy.Y - link.Y, enemy.X - link.X)

// Offset angle based on 45 degres (so we are checking angle based on an X shape, not a + shape).
angle -= 45;

// Work out direction.
direction = angle % 90;

// If direction <= 0 Then Face Up
// If direction == 1 Then Face Right
// If direction == 2 Then Face Down
// If direction >= 3 Then Face Left
« Last Edit: November 12, 2011, 04:08:39 pm by Infini »
Logged
Re: Wizzrobe
« Reply #2 on: November 12, 2011, 06:41:08 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 262
Thank you for responding to my request.
Unfortunatley GM does not have the atan2 function.
It has a arctan2 function, but I'm not totally certain if that works the same.

I've done another try for finding something usefull with google which has lead me to the point_direction option.
I've now made the following code to check the direction the Wizzrobe should face.

Code: [Select]
var dir;
dir = point_direction(self.x,self.y,obj_link.x,obj_link.y)
if (dir<45 and dir>0) then {direction = 0}
if (dir<0 and dir>315) then {direction = 0}
if (dir<135 and dir>45) then {direction = 90}
if (dir<225 and dir>135) then  {direction = 180}
if (dir<315 and dir>225 ) then {direction = 270}
Logged
Re: Wizzrobe
« Reply #3 on: November 12, 2011, 07:43:35 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
That's why it's call pusedo-code :). atan is short for arctangent, I imagine arctan2 does the same thing. Best read up on some trig :3. I imagine point_direction is just wrapper for arctan2 as well.
« Last Edit: November 12, 2011, 08:15:22 pm by Infini »
Logged

thestig

Re: Wizzrobe
« Reply #4 on: November 12, 2011, 11:32:55 pm »
That's why it's call pusedo-code :). atan is short for arctangent, I imagine arctan2 does the same thing. Best read up on some trig :3. I imagine point_direction is just wrapper for arctan2 as well.
Viva la Trig!
Logged
Re: Wizzrobe
« Reply #5 on: December 15, 2011, 04:12:18 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
I know this is rather late, but if you like to know the solution I would use. It is in pseudo code though.

Code: [Select]
top = link.y < (link.x - wizz.x) + wizz.y
left = link.x < -(link.y - wizz.y) + wizz.x

if(top && left)  wizz face top
else if(!top && left) wizz face left
else if(!top && !left) wizz face down
else wizz face right                         // (top && !left)
« Last Edit: December 15, 2011, 04:40:37 pm by Niek »
Logged
Re: Wizzrobe
« Reply #6 on: December 30, 2011, 09:20:35 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 262
well, every reply is always appriciated, even if it has been solved. Every code even pseudo code has the potential for me to learn something.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.062 seconds with 51 queries.