playMaker

Author Topic: Really THROWing something.. like hard!  (Read 2876 times)

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Really THROWing something.. like hard!
« on: April 02, 2016, 04:40:46 PM »
Lets say I making a Rockstar Hotel room trashing game? I pick up stuff in the room, (by hovering over it for more than 1 second- this game has NO keyboard controls or interface...) after a while (random amount of time) I wanna throw that stratocaster (or TV or lap or.. etc) straight out infront.

Ive been playing with Add force and add velocity,but cant get any results. Theres a few things to do at once, (like turn off gravity while holding the object? but snapping it back on when the force happens - do it will hit other stuff in the room)

Am I on to something, but just need the right settings? Or am I aproaching this all wrong?

Thanks in advance..

Mark

 

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Really THROWing something.. like hard!
« Reply #1 on: April 16, 2016, 04:49:26 AM »
BUMP!
OK, along time later, still trying to tweak this.

Heres the thing:
I pick up an object by hovering over it for more than 2 seconds.
(It is parented to the player and gravity is switched off)
Random time elapses
Object is thrown using a force away from player.

SO I NEED HELP WITH..

Getting the DIRECTION of throw right---
At the moment the throw works, but I think its always in the same direction, Z or something. I want it to be throw out directly IN FRONT of me.

I tried to pick up the vector with Get Position,


and feed that into my Add Force action...



but that resulted in something..- but not right...  kinda flew off to the right, can cant tell if its related to player position at all, seems a bit random... not the same every time...

Any help, and action suggestion appreciated!

terri

  • Sr. Member
  • ****
  • Posts: 386
    • terrivellmann.tumblr.com
Re: Really THROWing something.. like hard!
« Reply #2 on: April 17, 2016, 09:08:19 AM »
You could use Set Kinematic instead of turning off gravity.

You are throwing the item forward on its own Z axis.
Try parenting the item and then setting its rotation to 0 0 0 (self) before throwing it, see if it works.

Play around with different force modes, Impulse might not be the best one.

Also, you are getting the position, and calling it direction? Those aren't the same at all, but then you don't really use it anywhere so what's the point?


markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Really THROWing something.. like hard!
« Reply #3 on: April 18, 2016, 03:17:32 PM »
Thanks for the reply..
just out of interest, what does setting to Kinematic do that turning off gravity doesnt? never completely understood that.

>You are throwing the item forward on its own Z axis.
YEah so I need the Z of my player right? How can I "GET that"? Is it get rotation Z, then feed THAT var into the force Z?

When you say parent it.. I am doing that, thats how Im able to carry the guitar around... but when you say set its rotation to 0,0,0-- isn't that going to make it turn around?

You are right the example doesnt show me actually using the vector... its left over from trying all sorts of stuff...

Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: Really THROWing something.. like hard!
« Reply #4 on: April 18, 2016, 06:54:05 PM »
Hi,

In the game Im working on now I have a guy throwing a sphere forward. What I remember doing is:

I added a cube game object a few metres (estimate) in front of my character and removed its collider and mesh renderer.

Then when my character spawns a sphere in his hand to throw, I make the sphere look towards the invisible cube and add force to the sphere's z axis.

The sphere spawns in front of my character and rotates to face the invisible cube, then it flies towards it and falls to the floor as it flies (as gravity is enabled).

The invisible cube almost acts like a target for it (and could be made into a crosshair by adding a canvas and image, I imagine).

I think this would work for your guitar setup, just instead of spawning the object; unparent it, turn on gravity, look towards your invisible cube and then add force on the z axis of the guitar (as it is looking forwards at your invisible cube, it will fly forward)- then adjust the height of the throw by also adding force on the y axis.

Alternatively you could just add force in the direction of the invisible cube without using the look towards action and this should also work in theory...

Also beware that colliders may push you around a bit when thrown, I had to spawn my sphere without colliders and then enable them in mid flight. Before I did that everytime I threw a sphere it pushed my character backwards. (so in your case if the guitar usually has colliders- disable them just before unparenting and enable a second or so later. I had to play around with the timing until it stopped pushing my char backwards).

Hope this helps or something. Good luck with it!

(edit to add: I made a quick video of how my guy looks when he is throwing his spheres. My distance is set quite low on purpose: . As always I hope this helps and is simmilar to how you want to throw things).

(edit to add: I also always wondered exactly what kinematic does. Sometimes I find it useful through experimentation, but that is it lol.)
« Last Edit: April 18, 2016, 07:14:11 PM by Zeldag »

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Really THROWing something.. like hard!
« Reply #5 on: April 19, 2016, 04:26:32 PM »
@Zeldag That is very interesting... So the invisible cube is really acting as a target, and as its alwasy infront of the player, thats where you spheres go (You didnt mention that the cube is parented to the player, but I guess thats obvious)

Two things about what you said
The sphere spawns in front of my character and rotates to face the invisible cube, then it flies towards it and falls to the floor as it flies (as gravity is enabled).

Does this meant that IF YOU COULD SEE THE sphere rotating, it would appear to rotate? (errrr) Cos with my guitar that would be noticable..
and
secondly, How are you actually getting the sphere to fly towards the cube... are you saving the cubes position as a um... vector,and then using THAT in the position field of the Force action?

You have given me something to think about...

I get what you mean about the force pushing your player.. I don't think thats happening to me, but with me new implementation, (not quite the same as above)
I am getting me required functionality IF I can stay away from walls when I pick it up. Then the guitar parents nicely infront of the player and flies out in front.. BUT if IM near a wall, the guitar cant FIND that nice position and ends up in some weird place... Its almost OK.. I may leave it as a "fun feature". But I think it may result in some fails where the guitar can "break through" teh walls of teh room as it parents to you, and then when you throw it it flies 100 meters outside...

Ill try and do a video to, just for fun! Watch this space!


markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Really THROWing something.. like hard!
« Reply #6 on: April 19, 2016, 04:59:01 PM »
OK made a video (this serves another purpose so I dont get into guitar throwing til after a few moments)
:)

https://youtu.be/B2aoZroe3kA

As you can see, a "a careful" pick up of the guitar results in a good parented position and a good throw. The trouble comes if the guitar is strangely positioned against another object or wall when I pick it up.. then it parents a bit odd, and spins. Its OK, maybe I can live with it, but Id prefer it if it was a more robust system that didnt do this...

Im going to give your turning off colliders suggestion a go... but I have a feeling the guitar is just going to fall threw the floor sometimes...

« Last Edit: April 19, 2016, 05:31:35 PM by markfrancombe »

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Really THROWing something.. like hard!
« Reply #7 on: April 20, 2016, 03:18:50 PM »
Little UPDATE: Still not perfect.

So I tried @Zeldags suggestion of parenting a cube in front as a Force target.
This worked VERY well.-.- So thanks for that! I don't think it was needed if it wasn't for my second point.
SECOND POINT:
That with gravity on IF i pick it ip a bit weird, OR pick it up when its next to a wall, then it tries to parent itself into the position I have specified, but cant (wall in the way...) now this means that its offset in my view and actually spins... sometimes SO offset I cant see it.
What Id like is to somehow FORCE it to my position, maybe even pushing me back into the room to make it happen.

So I tried @Terri suggestion of using Kinematic. So I turn that on when I pick it up and turn it off when I throw it. THIS WORKED PERFECTLY!!!! I always pick it up neatly, so it always throw nicely!
BUT FOR ONE SMALL THING!

If I walk up to a wall, the collider doesn't seem to work, guitar goes straight thru, and when the "throwing" action arrives.. its throw from the room...

So no cigar just yet!