How do I would I change the angle of an object using a function and loop?

0 favourites
  • 11 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • hey, I'm a good bit confused on something. I was trying to make something where I could just input a variable for multi-shot then it would make multiple bullets and set the angle for each one of them individually without me manually setting them. when I did it, it made another bullet (I have no clue where it's getting that position) and it did to 3 bullets which only works when the gun angle is at 0. the more it goes the larger the gap gets.

    my event sheet for the weapons

    if anyone knows how to get something like this working properly that would be extremely or just knows what I'm doing wrong I'd be extremely appreciative

    best pic I could get to show what it's doing

  • You are setting the bullets to an increasing angle so the gap will get bigger? You can add an instance variable to track each bullet and where it comes from, then pause the game and view them, first identify which ones are wrong. You can easily pick out the loopindex=0 and loopindex=max ones with specific identifiers. Also you mentioned something should only work when the angle is at 0 but there are no conditions for angle.

  • I meant it only works correctly when the gun angle is at 0 rather than it doesn't work at all.

    I understand the gap will get bigger after the fact but it's weird because I would imagine that the first and last bullet to be made would be where they should be due to the fact it's simply just -25 for min angle and +25 for max angle. if only the middle bullet was doing that I'd understand

    also I did what you said. I fixed the issue where too many bullets appear and found out it seems like the start and end bullets are the ones that positions are all messed up but idk why when I'm picking the weapon by the UID and it has the same thing as the bullets that are in between

  • I just saw it for that particular problem, it's because in the action you have a typo and used imagepointX instead of imagepointY

  • oh damn, I didn't even see it, tysm, still the middle one's angle is messed up but it's no longer the position of the bullets. do you have any idea how to do what I want it to do?

    I want it to just be between the min and max but also be able to add more bullets and they stay between the min and max angle I have for it.

  • That's down to your formula in the first condition and up to you. Maybe if you multiply by loopindex it goes to high so you'll have to work out some approximate values you want for each bullet and apply.

    If you add the condition while bullangle is less than maxangle then I guess it can never create a bullet above the maxangle.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • well I want all the bullets to be evenly spread between the max and min angle

    so if you have three bullets the bullet in the middle is just straight down the middle, but if I were to add another bullet it'll split the two evenly

  • doing something like what you're saying would end up with any bullet that doesn't fit between max and min just to be either the max angle or min angle rather than in between

  • doing something like what you're saying would end up with any bullet that doesn't fit between max and min just to be either the max angle or min angle rather than in between

    It just wouldn't create the bullet because the condition would be on the left and the action for create is on the right. If the angle is too high it wouldn't create it. But it sounds like you want something more specific anyway so for this maybe what you could do is take the difference between min and max angle, divide it by the number of bullets you hope to spawn, then on each iteration of the loop add this value to the angle. So if min is 0 and max is 40 and you spawn 4 bullets, it would add 10 to angle each time.

  • this helped so much lol, finally got it working perfectly

    working with 3 or 11 bullets lol, honestly was super helpful ty

  • no problem, glad it's working!

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