The Daily Click ::. Forums ::. Klik Coding Help ::. Set bject direction based on another
 

Post Reply  Post Oekaki 
 

Posted By Message

-Liam-

Cake Addict

Registered
  06/12/2008
Points
  531

Wii OwnerIt's-a me, Mario!Hero of TimeStrawberry
8th January, 2013 at 08/01/2013 15:07:15 -

Okay! So this sounds like a really easy problem to solve, and maybe it is, but it's caused me hours of messing around now.

Basically, I have a character and 4 projectiles he can throw. The projectiles are separate active objects, with pinball movement. Their initial direction can be either 12 or 4 (Diagonal). The idea is when you press Button 2, a number is generated between 1-4, then a separate event will say the following:

IF - Player is Facing Right
+ - Value is 1
THEN - Set Projectile Right
+ - Create Projectile relative to Player

(I then have the same event, only changed based on the different values)

For some reason, the projectiles still go either left or right. Now the funny thing is, I had the same set-up working before when it was working with only 1 projectile. I did this by creating the object in the event which would generate a random value between 1-4.

I also have told the 4 projectiles to base their direction on the player's direction in the Button 2 event, but it still doesn't work. I even tried "Always set direction to that of player", but that just continuously positioned the projectiles at the player's position. (I didn't use the position action for this..?)

Maybe I'm just being dumb but it seems to me like this should be working? Can you think of another way?


Edit: The SECOND I hit post I noticed the title typo... :I

Edited by -Liam-

 
Image

Tell 'em Babs is 'ere...

Jon Lambert

Administrator
Vaporware Master

Registered
  19/12/2004
Points
  8234

VIP MemberWii OwnerTDC Chat Super UserI am an April FoolSSBB 3265-4741-0937ACCF 3051-1173-8012360 Owner
8th January, 2013 at 08/01/2013 16:19:36 -

"Always set direction to that of player" would have made them turn around and head back towards the player object as soon as they got any reasonable distance past it, if I'm right in thinking that you used the "Look in the direction of..." action. If your event is laid out exactly as I see it written there, then haven't you just put the actions in the wrong order (that is to say that you should have put the change direction action after the creation action)?

 
Sandwich Time!Whoo!

JoyCheck & KeyCheck Widgets
For easy implementation of customizable joystick and keyboard controls.
http://www.create-games.com/download.asp?id=8364

-Liam-

Cake Addict

Registered
  06/12/2008
Points
  531

Wii OwnerIt's-a me, Mario!Hero of TimeStrawberry
8th January, 2013 at 08/01/2013 16:45:16 -

Thanks for the reply! You know, I was just thinking about event order earlier... The thing is it worked this way when I had just one projectile as I copied the events over from before. I guess I must have done something else I had forgotten about previously.

Anyway, it makes more sense to me now so I'll give it another go - thanks for pointing this out!

Edit: Yes it worked - I don't know what I was thinking!

Edited by -Liam-

 
Image

Tell 'em Babs is 'ere...

s-m-r

Slow-Motion Riot

Registered
  04/06/2006
Points
  878

Candle
8th January, 2013 at 08/01/2013 19:49:58 -

I've done some thinking on this...What I would do in your situation is create a single object, but have the different objects displayed on the different animation frames of the object. Then once the object is created, record the direction the object will go and generate an Alterable Value from 1 to 4 within it. The animation frame shown is based on the Alterable Value.

Note that this option WILL NOT work if each different object is animated, but if they're static then this method may be helpful to you. It would look kinda like this:

IF Player is facing Direction [Right]

AND IF "x" is pressed [this is the key or button used to throw the object]
THEN Create Object "Projectile" at 0,0 of Player [change the coordinate relative to the one you want]
AND THEN Set Alterable Value B of Projectile to 1
AND THEN Set Alterable Value A of Projectile to Random(1-4)+1


Do the same thing for when the player is facing left, but change Alterable Value B:

IF Player is facing Direction [Left]

AND IF "x" is pressed [this is the key or button used to throw the object]
THEN Create Object "Projectile" at 0,0 of Player [change the coordinate relative to the one you want]
AND THEN Set Alterable Value B of Projectile to 2
AND THEN Set Alterable Value A of Projectile to Random(1-4)+1


Set a separate Event to indicate the direction the object.

IF Alterable Value B of Projectile = 1

AND IF Always
THEN Set Direction of Projectile to [Right]
AND THEN Set Alterable Value B of Projectile to 3 [this allows the Projectile to bounce as a pinball after being generated]


Do the same thing, but for the Left direction:

IF Alterable Value B of Projectile = 2

AND IF Always
THEN Set Direction of Projectile to [Left]
AND THEN Set Alterable Value B of Projectile to 3


Finally, there's one more event for each of the Projectiles.

IF Alterable Value A of Projectile = 1

AND IF Always
THEN Force Animation Frame of Projectile to 1


Do the same thing for the three remaining projectile types (three more events).

I seem to recall doing something similar for one of my projects a while back, so although I'm not always perfect on the Events related to animations this ought to work.

Edited by s-m-r

 
n/a

-Liam-

Cake Addict

Registered
  06/12/2008
Points
  531

Wii OwnerIt's-a me, Mario!Hero of TimeStrawberry
9th January, 2013 at 09/01/2013 20:51:01 -

Thanks for that smr! Unfortunately my projectiles are animated, but this is a nice method - I'll be sure to pop back in here later as I'll probably have power ups later on which aren't animated.

 
Image

Tell 'em Babs is 'ere...
   

Post Reply



 



Advertisement

Worth A Click