playMaker

Author Topic: Jumping!!!  (Read 7640 times)

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Jumping!!!
« on: March 01, 2013, 11:31:39 AM »
Im still awaiting help for a few issues in another thread...
http://hutonggames.com/playmakerforum/index.php?topic=3255.0
But have another which is maybe more "generic" and simple to answer.

In making a 3rdperson controller (which I will of course share to the forum when Im done...) Im discovering all sorts of tricky things I hadn't thought of!! :)

So now, to JUMPING!

When my man jumps its really just hooking up a couple of jumping animations to the space bar. An this works (nearly) flawlessly (see other thread!!) but of course, Im not actually moving the collider up at all! So its not any actual use in game, just visual!
SO I need to move the whole model (or just the collider) up on SPACE BAR, and down again to whatever is below him, terrain/floor etc.

I tried a translate up along Y, but he just sticks in mid-air and gets higher on each jump.

Whats the best way?

Mr-Brett

  • Playmaker Newbie
  • *
  • Posts: 22
  • Not very technical Artist
    • Portfolio
Re: Jumping!!!
« Reply #1 on: March 01, 2013, 12:26:01 PM »
I had the same problem (more or less) with that tutorial's jumping.

I remembered there was an official tutorial for making a box jump though so I went back and watched that. Starting from there I've modified it to here:



JumpHeight is just a float I use so I can set jump height out of the fsm and the rest should be familiar.

It's far from perfect, I get some flakey results at times with collision but hopefully it'll help.

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Jumping!!!
« Reply #2 on: March 02, 2013, 10:06:17 AM »
Good Afternoon Mr Brett!
(your name makes me feel like being formal :) )

Thanks for that, its pretty much working. I have a couple of questions,
QUESTION ONE
Im getting a little jitter just when I hit JUMP, like one frame of him at the top of the jump height... do you think this is to do with the curve?
QUESTION TWO
Secondly, where are you adjusting jump height, do you mean when you say
Quote
I can set jump height out of the fsm

That you have a place where you are globally adjusting jump height? or Just that you go into the variable window and adjust the default value of the float?

Did you actually finish your controller or is it still Work in Progress?
At every stage I discover some new tweak I need to do, and that in turn throws up more tweaks!!!

For example I have added a different jump for when he is stood still.
Ive also added (or am trying to add, not quite working) a shuffle animation for when you turn on the spot but are not moving forward, the avatar shuffles his feet.
And Im trying to fix a bug with the tutorial system, where if you press the run button BEFORE pressing W, then it doesn't go to run immediately. Mine does now. But.. now I have a bug where after releasing W and he goes back to idle, BUT you STILL havent released leftShift for RUN,  it doesnt recognise that the button is still pressed down... I didnt realise but it seems that the GetKeyUp action only notices when the button CHANGES state, IE, is pressed, not if the button is already pressed... Seems I need to set variables by the GetKeyUp instead, and have the variables control the action, instead of the Key up...
(just thinking aloud here )

hope you can answer the couple of things here...

thanks for your help, I really didnt think I could write a controller all in PlayMaker, but here I am... All due to you!! kudos!

MArk


« Last Edit: March 02, 2013, 10:08:33 AM by markfrancombe »

Mr-Brett

  • Playmaker Newbie
  • *
  • Posts: 22
  • Not very technical Artist
    • Portfolio
Re: Jumping!!!
« Reply #3 on: March 02, 2013, 10:50:27 AM »
Mr Brett or just Brett, either is fine.
It was a name I started using online many years ago and it just stuck.

That's very nice of you to say but it's not all due to me, it's in big part to that tutorial video (imperfect as it may be) and mainly to you! give yourself some credit :)

Q1 - I'm not sure but I expect it is the curve, you can try changing it a bit maybe raising or lowering the high point but I have to admit I don't fully understand how it works...

Q2 - I mean that I tick the 'inspector' option in the variables panel which allows you to edit the variable in the inspector panel when the object is selected. It can be helpful if you have complex FSM's but doesn't save that much time really.

Like you I'm still tweaking mine regularly but it's more or less done, being first person and having no animation really saves me a lot of hassle by the sounds of things ;)

I'm not sure if I completely follow your thinking aloud bit but using variables does seem like the way to go, if you'll allow my to go way off topic I'll waffle on about something I did yesterday:

I added some sounds, footsteps and an ambient track. You'd think it'd be simple to do but was harder than I expected, to get the footsteps to play at the right time I thought of using the idle/walk/run transition as inspiration, so I linked it to the player magnitude. I didn't want the same footstep sound though so I have 5 slightly different ones with a play random sound action. 
Great so you start moving and it plays, but only once. So eventually I figured that I couldn't set it to loop so I needed some other method, so I added a wait (very useful action) and set it to 0.25 before it sends it back, the float compare registers that magnitude is still higher than 0 so it sends it back to the sound action and bam, we have a loop (of sorts).
Ok that's great but what about when you're running? the footsteps should increase in speed right? after plenty of messing around I finally had the idea (which seemed to me to be inspired but would probably seem pretty obvious to most) to have the time in the wait action as a variable and have an action that changes the wait time also dependant upon the magnitude, so when it got above my set walk speed it'd change the variable. Sorted!

After trying many different complicated additional fsms and actions it was actually a variable that did the job much better and more elegantly (with a simple fsm).

Sorry about the long explanation there, I'm hoping it gives you some ideas. :)
« Last Edit: March 02, 2013, 10:57:38 AM by Mr-Brett »

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Jumping!!!
« Reply #4 on: March 02, 2013, 12:33:19 PM »
Quote
Sorry about the long explanation there, I'm hoping it gives you some ideas
Definitely! I like the cut of your jib Sir! Im an over explainer here myself!

Footsteps!! DAMN!! Of course I need footsteps!! Of course where I would be wanting to take this even further, is to have different footsteps dependent on what ground you were on!! Stone, earth, or floor... probably into tagging now wouldn't you think?

Mr-Brett

  • Playmaker Newbie
  • *
  • Posts: 22
  • Not very technical Artist
    • Portfolio
Re: Jumping!!!
« Reply #5 on: March 02, 2013, 01:45:59 PM »
Tagging? as in the unity tags for objects? I haven't used that yet, I should probably look into it.

Could you tag materials and have playmaker get the tag data? if so I don't think it'd be too hard to set up the actions in playmaker. You could feed it into a variable, when movement is registered and the action for footsteps is sent you could have a check to see what tag is in the variable and send to the correct sounds action.

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Jumping!!!
« Reply #6 on: March 02, 2013, 03:15:59 PM »
I think that sounds about right, Im not sure what you could do about terrain though? Of course footsteps needs to change from fields to snow to sand.. which I dont think you can really specifiy with tags. Luckily my roads are not just textures on the terrain but a mesh so I can tag that differently than the terrain.

I think that the Bootcamp demo has, (what shall we call them?) dynamic footsteps, might be worth looking at how its done in code...

Mark

Mr-Brett

  • Playmaker Newbie
  • *
  • Posts: 22
  • Not very technical Artist
    • Portfolio
Re: Jumping!!!
« Reply #7 on: March 02, 2013, 08:19:29 PM »
I can't seem to get the project from Unity's site, the page isn't loading for some reason but if you do check it out then let me know what you find :)

Another option could be trigger volumes. You set the default as whatever is the most common material and you put in volumes for any others. They're pretty easy to set up and should be cheap too but could become a bit of a hassle if you're making something big with lots of ground types.

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Jumping!!!
« Reply #8 on: March 03, 2013, 05:01:18 AM »
(Bootcamp should be free on the asset store)
Yes I was thinking about trigger volumes too...  as I have other stuff that needs triggering when entering areas...(snow, rain, music, sound fx) so Ill be setting up my whole game into areas. The only thing for me is roads, they are kind of different. Im thinking that Ill probably only use 3 types of footsteps, earth, road, and floor. floor being all interiors.

I searched my demo projects and found a few scripts, i think the Bootcamp one is this... appearing to work with tags.
Code: [Select]
public var footAudioSource : AudioSource;

public var woodSteps : AudioClip[];
public var metalSteps : AudioClip[];
public var concreteSteps : AudioClip[];
public var sandSteps : AudioClip[];

private var cc : CharacterController;
private var t : Transform;

public var hitLayer : LayerMask;
private var cTag : String;

function Start()
{
cc = GetComponent(CharacterController);
t = transform;
}

function OnFootStrike ()
{
if(Time.time < 0.5) return;

if(cc != null)
{
volume = Mathf.Clamp01(0.1 + cc.velocity.magnitude * 0.3);
}
else
{
volume = 1;
}

footAudioSource.PlayOneShot(GetAudio(), volume);
}

function GetAudio() : AudioClip
{
var hit : RaycastHit;

//Debug.DrawRay(t.position + new Vector3(0, 0.5, 0), -Vector3.up * 5.0);

if(Physics.Raycast(t.position + new Vector3(0, 0.5, 0), -Vector3.up, hit, Mathf.Infinity, hitLayer))
{
cTag = hit.collider.tag.ToLower();
}

if(cTag == "wood")
{
return woodSteps[Random.Range(0, woodSteps.length)];
}
else if(cTag == "metal")
{
return metalSteps[Random.Range(0, metalSteps.length)];
}
else if(cTag == "concrete")
{
volume = 0.8;
return concreteSteps[Random.Range(0, concreteSteps.length)];
}
else if(cTag == "dirt")
{
volume = 1.0;
return sandSteps[Random.Range(0, sandSteps.length)];
}
else if(cTag == "sand")
{
volume = 1.0;
return sandSteps[Random.Range(0, sandSteps.length)];
}
else
{
volume = 1.0;
return sandSteps[Random.Range(0, sandSteps.length)];
}
}

THEN I found this one from a free monster pack thingy, you add one script to your model and one to the geometry you want to walk on....
I havent tried this, but its might be another way to think... especially if the object that you walk on actual contains the reference to the noise the footsteps would make on it... again, not really working on terrain. But I imagine it could be good in a house, imagine moving from wooden floor, to stone kitchen floor, to carpet...

Anyway, something to study..

FIRST THE SMALL SCRIPT THATS ADDED TO OBJECTS
Code: [Select]
// Small script to hold a reference to an audioclip to play when the player hits me.

// This script is attached to game object making up your level.
// The "Foot" script (which is attached to the player) looks for this script on whatever it touches.
// If it finds it, then it will play the sound when the foot comes in contact

var audioClip : AudioClip;
var volumeModifier = 1.0;


AND NOW THE ONE THAT YOU ADD TO CHARACTERS...

Code: [Select]
var baseFootAudioVolume = 1.0;
var soundEffectPitchRandomness = 0.05;

function OnTriggerEnter (other : Collider) {
var collisionParticleEffect : CollisionParticleEffect = other.GetComponent(CollisionParticleEffect);

if (collisionParticleEffect) {
Instantiate(collisionParticleEffect.effect, transform.position, transform.rotation);
}

var collisionSoundEffect : CollisionSoundEffect = other.GetComponent(CollisionSoundEffect);

if (collisionSoundEffect) {
audio.clip = collisionSoundEffect.audioClip;
audio.volume = collisionSoundEffect.volumeModifier * baseFootAudioVolume;
audio.pitch = Random.Range(1.0 - soundEffectPitchRandomness, 1.0 + soundEffectPitchRandomness);
audio.Play();
}
}

function Reset() {
rigidbody.isKinematic = true;
collider.isTrigger = true;
}

@script RequireComponent(AudioSource, SphereCollider, Rigidbody)

Mr-Brett

  • Playmaker Newbie
  • *
  • Posts: 22
  • Not very technical Artist
    • Portfolio
Re: Jumping!!!
« Reply #9 on: March 03, 2013, 06:53:58 AM »
Wow, nice job.

My code-fu is pretty poor but if I'm understanding that correctly it fires a raycast down from the player to check the tag of the model below?
Interesting and it seems you could do it in playmaker too.

Attaching the sounds to the object and having it play on hit is cool, that way you could probably make it a 3D sound and have it play where ever the hit takes place with a set position or something although I did try setting the footstep sound to play at the feet of my character and it ended up lagging behind a bit which made it sound like someone was following you, creepy.
It's probably must less important for a third person game anyway I expect.

There must be some solution to the terrain issue, other than volumes that is. Something more procedural... hmmm. How do you handle your terrain blending? vertex colours?

Avascar

  • Playmaker Newbie
  • *
  • Posts: 45
Re: Jumping!!!
« Reply #10 on: March 24, 2013, 08:45:51 AM »
Tried your method with the Get Position, Set Position, and Animate Float V2, although my player only jumps slightly. I tried changing the variable, Animate Float V2, and almost everything (except Get Position). What am I missing??

EDIT: Nvm, it was the anim curve in Animate Float V2. Although it doesn't follow the height on my float, rather on the curve. Is this how it's supposed to work?? (but even if it is based on the curve, I jump mighty low.)
« Last Edit: March 24, 2013, 08:51:26 AM by Avascar »

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Jumping!!!
« Reply #11 on: March 24, 2013, 04:30:08 PM »
I must say that I have gone away from this method too myself. I first read jeans explanation for jumping.
http://hutonggames.com/playmakerforum/index.php?topic=1951.0
and now im experimention with
http://hutonggames.com/playmakerforum/index.php?topic=3413.0

who seems to be on to something...

I did manage to get a good jumping FSM using the above method, but Its very unweildy, and any small change somewhere in my system kind of threw off a lot of other stuff...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Jumping!!!
« Reply #12 on: March 25, 2013, 01:06:33 AM »
Hi,
 
Can you elaborate on what becomes unstable when you modify? there might something I can help you with here.

bye,

 Jean

greg

  • Junior Playmaker
  • **
  • Posts: 68
Re: Jumping!!!
« Reply #13 on: March 25, 2013, 08:39:51 AM »
- Get the vector3 you're using to move your controller each frame
- If grounded and spacebar is pressed, set the Y value to -jumpHeight
- otherwise set the value to your gravity amount (20)

^do this with "convert bool to float", and set your Y amount according to whether jumpKey is true/false

If grounded you'll likely need to set gravity to 0.001 which solves a "grounded?" issue with unity controllers
« Last Edit: March 25, 2013, 08:43:55 AM by greg »