0 Favourites

How do I Spawn Object At Angle From Another Object

  • I would like to have a collectible 'pop' out once a crate is broken. I've tried using the Crate--> Destroy-- Create Object & System Create Object --> but it only creates it at the Crates Origin.

    I know how to create Object at specific X & Y points and at a random angle, but not from a specific object (the crate) or at a random angle.

    I've tried System-->Create Object--> Apple--> crate.x crate.y but i'm missing something with the random angle expression.

    If anyone could help i'd be most thankful

  • Can't you just set the apple to have a random angle when it's created?

  • When a crate is destroyed it creates the apple (and assorted fruit). I'd like the fruit to 'pop' out of the crate making the player go and pick it up.

    So i have to create the fruit at the crate and set the angle from the crate as well. I'm not sure exactly how to do this.

    So far I have

    On the create sprite 2 (crate.y, crate.x) action I'm missing something in the random(35, 40) expression.

    I tried = crate.Y(random(35, 40))

    I'm not exactly sure how to write the expression after crate.y, crate.x

  • Erm so if your game is strictly 2D (like a platformer) and you want the apple to pop out at a random trajectory (I assume that's what you mean by angle) you can give the apple the platform behavior but set the default controls to NO in the behavior settings for the apple.

    Playerbox1 - On Collision with Crate | Crate - Spawn another object Sprite 2 on Layer 3  ImagePoint 0
    PlayerBox1 - Y < Crate.Y             | Crate - Spawn BreakCrate on Layer 3 at ImagePoint 0
                                         | Crate Destroy
    [/code:1qgv9rth]
    
    This is how you should structure the first part of your code. After this you should do this:
    
    [code:1qgv9rth]Apple - On Created | Simulate platform pressing UP
                       | Simulate platform pressing RIGHT[/code:1qgv9rth]
    
    This method doesn't give it a random trajectory but it should work. To make it random you might want to use the bullet behavior on your apple and give it a random angle of motion when it is spawned.
    
    I hope I understood what you were asking for.
  • Hey thanks Aleyba.

    I think you do. Basically, imagine if someone were inside a box and they tossed out an apple.

    I'm not too worried about the random angle as much as i am about it popping out away from the crate. Right now when the player breaks the crate an exploding animation plays as the apple is created in the spot of the crate.

    Two problems with this: 1) there is too much going on in that 48px area and 2) as soon as the player breaks the crate and the apple is created it disappears. You really don't even see it. I've tried 'pausing' the Apple Destroy but it looks/ plays weird.

    I'll give your method a try.

    Thanks again for the help.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • No problem. If anything just use the bullet instead of the platform behavior. Give the bullet some gravity in the behavior settings. When the apple is spawned set the angle (probably to 90) so that it will shoot upwards and come back down.

    You can tweak it to give you a random angle each time. Just make sure to make the random number between 180 and 0 degrees each time. ( Or whatever you want.)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
99 10,139
karshinkoff's avatar
karshinkoff
Unread hot topic
167 14,500
DMT2005's avatar
DMT2005
Unread hot topic
123 14,873
Zebbi's avatar
Zebbi