#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# touch to lob actor

Posts: 486Member, PRO
edited September 2017

Hi all..

Am tinkering with the idea of trying to get an actor to move to touch – but to travel up and drop down kinda like a ball being thrown at a basket ball hoop. Can anyone help here?

«1

• Posts: 402Member

Very nice idea.

My first attempt.
Gravity or a downward acceleration/motion is applied.

A drag/let go mechanism to shoot is applied to the actor(1) to make it jump.
Also an invisible New Actor is spawned.
When the airborne actor(1) collides with the New Actor the player must press them both in order to finish the move.

Rule applied to New Actor
When Actor collides with actor(1) and Touch is released.

Do

Hope this helps.

• Posts: 486Member, PRO

I think I might've titled this incorrectly. No actual slam dunk – more of a lob. I don't think I can use scene gravity as I have other actors that need to move.

• Posts: 486Member, PRO

anyone?

• Posts: 595Member, PRO
edited September 2017

Sorry mate, I struggle to make physics work in that respect - maybe you can apply an upward force/hit (Y Velocity) initially, and experiment with interpolate to get your actor to try and get to point B, after a set delay/distance is hit, to achieve a similar effect, but as regards the actual physics calcs to get it from A to B in a gravity-affect parabolic curve, over my head I'm afraid!

As regards Gravity, I'm assuming that we all either pin everything else, or just simulate it?
- ie. apply a constant downward force rule to the ball and other 'gravity' affected actors, etc? - that's what I'm doing with Parcel Monkey and Gravity Star Rescue Racer, and it works well...

• Posts: 11,296Member, Sous Chef, PRO, Senior Sous-Chef

I know there are demos of this... I feel like even official demos... if I can find one, I'll post it here.

New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

• Posts: 11,296Member, Sous Chef, PRO, Senior Sous-Chef

Here's an old official GameSalad demo that might do the trick.

New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

• Posts: 2,786Member, Sous Chef, PRO

You might need to give more detail. The more info, the better the suggested solution.

• Posts: 486Member, PRO
edited September 2017

Thanks @Japster – I'll have a go at what you've mentioned... and thanks @tatiang for the demo – the way that the canon ball travels up then comes down (gravity affected) is what I had in mind.

Though my idea involves the player touching the screen at the point where they'd like the ball to land. Still, the demo will give me something to go on.

@RThurman – Does the above help in any way to clarify what I'm trying to do here?

Basically the goal is as follows:

• Ball is sitting stationary at the beginning of the game.
• Player wants the ball to travel up and land via an arc by touching where they want it to land. (just like the cannon ball in the above demo)
• The tricky bit is that I have other actors that I want to interact/move and not be affected by any scene gravity.

Is this possible?

• Posts: 595Member, PRO

@monkeyboy simian said:
Thanks @Japster – I'll have a go at what you've mentioned... and thanks @tatiang for the demo – the way that the canon ball travels up then comes down (gravity affected) is what I had in mind.

• Player wants the ball to travel up and land via an arc by touching where they want it to land. (just like the cannon ball in the above demo)
• The tricky bit is that I have other actors that I want to interact/move and not be affected by any scene gravity.

Is this possible?

Yep, I'm sure the guys will help too, but you need a rule that applies force downwards, to your ball - hence only simulating gravity, so that you can then ensure that gravity is switched off if nothing else should behave as if affected by it. Or you could perhaps pin everything else, but the problem with pinning stuff is that it can be glitchy unless you add ludicrous amounts of mass to the stuff - otherwise you can hit them and they'll still move, then the engine will try to pull them back to where they should be - it looks ugly if not done right...

The thing about the method I mention is that the logic to 'movetowards' your target position should hopefully just drag it to there, whilst your upward force (initially high of course, and diminishing once you've 'fired' off the apply velocity behaviour, as your fake gravity behaviour will constantly be slowing it down in its upward ascent) is acting on it, causing the movetowards behaviour to re-evaluate and take this movement into it's equation.

Again, not at home so can't even knock up a quick example (roll on the web-based creator for that at least!), but I'm guessing it should work fine, after a tweak to find the best values for your faked gravity, and your initial upwards force!

• Posts: 2,769Member, PRO

@monkeyboy simian what does the ball do after it arrives at the touch position? Does it continue with normal physics behavior or stay stationary?

• Posts: 486Member, PRO

@Japster I'm currently trying out using 'move to' game.mouse.position.x/.y and accelerate 270° at 1100 (fake gravity) – which does show some promise.

I got them out of a template for a colorswitch knock off by sparky.

But it has to have game playing attributes applied as the ball obviously wants to fall immediately. So I'm chugging away at that with the 20 minutes that I've got left to work on this today.

@Hopscotch – I'd like the ball to behave in the normal physics way i.e.: bounce around a bit..

• Posts: 595Member, PRO
edited September 2017

@monkeyboy simian said:
@Japster I'm currently trying out using 'move to' game.mouse.position.x/.y and accelerate 270° at 1100 (fake gravity) – which does show some promise.

I got them out of a template for a colorswitch knock off by sparky.

But it has to have game playing attributes applied as the ball obviously wants to fall immediately. So I'm chugging away at that with the 20 minutes that I've got left to work on this today.

@Hopscotch – I'd like the ball to behave in the normal physics way i.e.: bounce around a bit..

That's a great start! Yes, the moveto logic takes care of the sideways movement, so 270 should be perfect, along with some value tweaking... once it hits your 'pad' of course, you can turn off the moveto logic, and it should bounce/behave as you want it to, after a normal collide...

PS - Is Accelerate helping? - I'd have thought that may look weird as it's getting faster over time? - maybe just apply/set Y velocity to a value (ie. 300, -400, etc (I forget which way is up when not in front of Creator!)), to give it an initial force, that then naturally diminishes on it's own via the physics engine, given the constant downward fake gravity behaviour in place, coupled with the effects of the moveto?

• Posts: 486Member, PRO

@Japster – I haven't had a lot of time unfortunately. I'm still buggering around with that accelerate. I'm hoping that the tweak factor will do the job. The thing that's annoying me at the moment is that the ball actor seems to shoot up rapidly but seems to lack the sort of lobbed feel I'm after. I'm going for movement like in colorswitch but with directional control (up, left, right).

Hey, by the way – I haven't noticed Socks or Armelline in the forums for a while. Are they still here?

• Posts: 595Member, PRO

@monkeyboy simian said:
@Japster – I haven't had a lot of time unfortunately. I'm still buggering around with that accelerate. I'm hoping that the tweak factor will do the job. The thing that's annoying me at the moment is that the ball actor seems to shoot up rapidly but seems to lack the sort of lobbed feel I'm after. I'm going for movement like in colorswitch but with directional control (up, left, right).

Hey, by the way – I haven't noticed Socks or Armelline in the forums for a while. Are they still here?

Hi mate - Yeah, it's why I mentioned above about accelerate - I don't think that's going to help mate - I think you literally just need to apply velocity upwards (NOT acceleration)

ie. set the actor's velocity to INSTANTLY be X amount... In addition to your fake gravity acting constantly on the actor, that will give you the effect you're looking for, I think.

Yeah, not seen either of those guys for a while - perhaps they're just busy, and hopefully not disillusioned to the point of not visiting (I was in that dark place for a while)...

• Posts: 486Member, PRO
edited September 2017

Thanks @Japster – Are you talking about 'change velocity'? I've just had a look at that but it doesn't allow you to send the actor to x and y positions. Any other ideas?
Currently I'm actually, I'm using 'move to' to propel the ball actor upward. Am going to explore change attribute next time I get to tinker..

I don't remember seeing you around here until quite recently, and I've been here since 2012 now..

• Posts: 595Member, PRO
edited September 2017

@monkeyboy simian said:
Thanks @Japster – Are you talking about 'change velocity'? I've just had a look at that but it doesn't allow you to send the actor to x and y positions. Any other ideas?
Currently I'm actually, I'm using 'move to' to propel the ball actor upward. Am going to explore change attribute next time I get to tinker..

I don't remember seeing you around here until quite recently, and I've been here since 2012 now..

@monkeyboy simian - Nope, I've been here since about 2013 matey, and posted a fair bit (I'm actually pretty vocal about lotsa stuff if you do a quick search, ha ha!), BUT, I left the forums alone for about 8 months when things were at their worst, and life was also getting in the way...

Yep, change velocity, or better still, you could just 'change attribute' linear velocity Y to a set amount - try that...

I'll have a play when I get home, but basically, you want to just perform the equivalent of throwing something up, or even class it as hitting something up, which also has the pull to a certain location acting on it, which should also decrease the vertical speed as it's happening - it may not work that way, but I'll also have a play now I've got 5 mins...

• Posts: 595Member, PRO

@Hopscotch said:
Here is my heavy-handed attempt.
It will need tweaking depending on the project but the maths is there.

The idea

Awesome mate! - physics calcs were never my strong point, hence my idea was of a simple fudge....

• Posts: 402Member
edited September 2017

Very nice @Hopscotch!

My bad, I misunderstood the idea.
Really couldn't have done that.

• Posts: 486Member, PRO
edited October 2017

thanks @Japster – I tried the change velocity of the actor (in the actor attributes, yes?).. couldn't make it work.

thanks @Hopscotch – The lobbing up at a specific spot effect is what I'm trying to do – it's just so hard core for me to try and work out what's going on there.. I've tried all of the various built in GS behaviours and none of them seem to do this.

Does anyone know of a simpler way to achieve the result? (as demonstrated above)

• Posts: 486Member, PRO

bump..

• Posts: 2,769Member, PRO
edited October 2017

@monkeyboy simian said:
I've tried all of the various built in GS behaviours and none of them seem to do this.

Did you see the project I attached? It is all GS behaviors. Just follow along. You may just need to adjust some parameters depending on the "feel" you are going for. The physics in the above are strictly according to earth gravity.

The maths is not really that wild.

• Posts: 431Member, BASIC

@Hopscotch

Very cool. Thanks for sharing!

Best,

• Posts: 486Member, PRO
edited October 2017

@Hopscotch – I did see the attached file.. the thing is that it made my tiny brain hurt. I can't work out what's going on in there. There's something called pheta, there's a max that I don't understand, so many constrains and attributes. I am grateful, just unable to comprehend. I'll try some more to work it out.. Why does the blue cross have an attribute called drag? Also, why does the constrain attribute in that actor have *15 in the expression? It also seems like once you fire off a couple of balls say to the right, it won't fire any off to the left. Again, I prove to be an intellectual oompaloompa.. I also found something called pow in there.. I have no idea what that means..

• Posts: 2,769Member, PRO
edited October 2017

@monkeyboy simian
something called pheta

this is the calculated launch angle (will check, but I don't think it is used anymore, it is left over from a different calculation. Sorry)

@monkeyboy simian
there's a max that I don't understand

The min() and max() functions in GS are quite useful. They return the smallest or biggest number in a collection of numbers respectively. Note: it can be more than 2 numbers.

Simple implementation:

to get the new high score -

in stead of using a rule:
`if NEWSCORE is greater than HIGHSCORE then make HIGHSCORE = NEWSCORE)`

just use the max() function:
`HIGHSCORE = max(HIGHSCORE,NEWSCORE)`

Mindbending implementation to put limits on numbers:

let us say you want an actor to follow the mouse, but only go between 200 and 700 on the X axis:
`contrain actor.positionX to max(200,min(700,mouse.positionX))`

This will prevent the value from going smaller than 200 or larger than 700.

@monkeyboy simian
it won't fire any off to the left

to simplify the calculation, I just took the right hand side into account and don't allow touches on the left side of the launch position. (but it would be simple to cater for any direction.)

• Posts: 486Member, PRO
edited October 2017

thanks again @Hopscotch – for the further explanation. Alas, I am a moron. Could you please elaborate as to how you only accounted for only the right side.. maybe this will help me unpick this..

also, with this bit:
contrain actor.positionX to max(200,min(700,mouse.positionX))

I would've thought that the max would be next to the 700 and the min next to the 200

Are those vertex actors making the lines that intersect?

• Posts: 2,769Member, PRO

@monkeyboy simian said:
also, with this bit:
contrain actor.positionX to max(200,min(700,mouse.positionX))

I would've thought that the max would be next to the 700 and the min next to the 200

That is why I gave it the "mindbending" heading.

max() gives you the biggest of a list of values. So if you want mouse.positionX to never be smaller than 200, then you use max(200,mouse.positionX)

If mouse.positionX falls below 200, lets say 150, then the function will return the bigger of the two values, being 200 - thus limiting mouse.positionX to never be smaller than 200.

The same for min() to make sure mouse.positionX never gets bigger than 700.

So, max(200,min(700,mouse.positionX)) is just the combination of the two.

@monkeyboy simian said:
Are those vertex actors making the lines that intersect?

Yes, they are just a visual representation of the maximum height the ball can travel, and the real midpoint between the launch point and the target.

• Posts: 486Member, PRO

could you please give me a clue about how you'd apply this to the left side? I'd really like be able to understand this..

• Posts: 486Member, PRO

I really need help here.. anyone? I just can't work this out. It's like trying to reverse engineer the Hadron collider.. Please, all I want to do is lob a ball. Surely this is not so complicated??

• Posts: 486Member, PRO

sigh..

«1