Set Bullet Angle Towards Another Object

0 favourites
  • 8 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hey hey,

    I am working on a platform game where the player collects coins/fruits etc. Upon touching the fruit I have enabled a bullet behavior on a set angle. This gives me a crude version of the effect I want.

    What I want to know is how would I set the bullet's angle of motion towards another object? I have tried setting its angle to the windowwidth/windowheight etc but that doesn't work after I start moving away from the initial start area, for obvious reasons.

    Basically, when an item is collected, I want it to snap to the top left hand corner and make the UI number go up by +1. Im sure most people here have seen this effect.

    Any help is greatly appreciated.

    Thank You,

    Stephen

  • Setting it to another object wouldn't work, as the UI object's actual position is always going to be off, owing to the UI layer's parallax property.

    Assuming that you have your UI object in the top left corner, you can set the object's bullet angle to angle(Collectable.X,Collectable.Y,ViewportLeft("Game"), ViewportTop("Game")). This will just send it off to the top left corner and not, strictly speaking, to the UI object itself, but the effect is the same.

  • GeometriX Okay, thanks for your help. I have implemented what you have shown me and I am getting the same result. I should have mentioned that I want the angle to update every frame.

    You see if the player is running and collects something, the item will actually end up going off the screen lower than intended. The same goes for the player running the opposite direction. The collectable will end up going off the screen somewhere near the top/middle of the screen.

    I am think I need create an Every Frame event, but I am not sure about how to go about this. I will play around with it in the mean time.

    Thank You,

    Stephen

  • Add an invisible sprite in your "Game" layer and give it Pin behavior. On start of layout pin it to your UI element.

    Change the fruit's behavior from bullet to custom movement and use "accelerate towards position". Set X,Y of your sprite and never look back ;-p

  • GeometriX Okay, thanks for your help. I have implemented what you have shown me and I am getting the same result. I should have mentioned that I want the angle to update every frame.

    You see if the player is running and collects something, the item will actually end up going off the screen lower than intended. The same goes for the player running the opposite direction. The collectable will end up going off the screen somewhere near the top/middle of the screen.

    I am think I need create an Every Frame event, but I am not sure about how to go about this. I will play around with it in the mean time.

    Thank You,

    Stephen

    Could you not create the object on a layer with its Parallax X and Y set to 0? That way the object's position would be independent of your movement layer. If you have a HUD layer, you could just move the object to that layer with Move to Layer, and you'd only have to calculate the angle once.

    Seems a bit more economical than constantly readjusting the angle.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This is what I am now using. I need to set the speed up to 10,000 just to get the fruit to move off the screen in under 2 seconds. I have pinned an object to my Game layout and set the paralax to 0,0 I can see it scrolling along with me. But the Fruit still try to go to 0,0 of the entire layout.

    <img src="http://img21.imageshack.us/img21/6581/quhh.png" border="0" />

    The .capx file

  • This is what I am now using. I need to set the speed up to 10,000 just to get the fruit to move off the screen in under 2 seconds. I have pinned an object to my Game layout and set the paralax to 0,0 I can see it scrolling along with me. But the Fruit still try to go to 0,0 of the entire layout.

    <img src="http://img21.imageshack.us/img21/6581/quhh.png" border="0" />

    https://www.dropbox.com/s/fslf5xkj8b5iwr0/FruitMovement.capx

    Unfortunately, I use an older version of Construct 2 so can't view your capx. I would suggest perhaps posting screenshots of the relevent code, rather than your entire game though. Unless you don't mind sharing your code of course.

    Where is it that you want it to go exactly?

    I haven't used custom movement myself. but once it reaches sprite.x, sprite.y, shouldn't you set the acceleration to zero?

    You could do this by creating a new event to check when the object is at position sprite.x, sprite.y, or when the object has collided with the sprite object, then set acceleration to 0. Or disable the custom movement entirely.

  • You have to move the fruit to the GUI layer. And bullet seems to work better than custom movement.

    fruit_movement.capx (r137)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)