Jump Block

Updated on July 6, 2015 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
13 on July 5, 2015

Hello guys so iam doing platformer and i was wondering how to make a blockthat will send u the direction u came from like u come from right u will be punched to right u come to top u will be punched to top and etc yeah i know i can just make few seperate scripts to add x z y and ontriggerenter them and add to 4 seperate collisions on same block but i was wondering can u do it simplier ? 

 #pragma strict
 var player : Rigidbody;
 var bounceAmount = 10f;
 function OnTriggerEnter () {
 player.GetComponent.().velocity.y = bounceAmount;}
 

i did it with all directions and surounded the block it works but its not the best way iam sure
and i was wondering can i increase it based on power like if unit comes from 10y he will be punched up with 15 if he comes from 20y he will be punched 25-30 up

  • Liked by
Reply
1 on July 5, 2015

Well if you want the player to just go in the way they are coming from just do

player.velocity = player.velocity*-1;
(This will be very jarring if you are using any of the standard assets movers. Since they directly change the velocity which means the x or z velocity is instant instead of a smooth move)
^= if player goes —–>*HIT* he goes <—-

and what do you mean if he comes from 20Y he will be punched 25-30 up?

as in you want that if he falls from a greater height he will be punched back more?(this would mean that said person gets higher velocity every time he gets blocked, if he lands ontop of the blocker:P)

just add like a * 1.2f to the above code

on July 5, 2015

thank you

Show more replies
  • Liked by
Reply
Cancel
1 on July 5, 2015

one little question why 1.2f i mean why f letter ? i did it based on tutorials so i added f but why ?

Guru
on July 5, 2015

It’s because it is a float. If you have a float that doesn’t have decimals it will not need the f. But if the float does have a decimal you will have to add the f or else the number won’t get recognized as a float.

Show more replies
  • Liked by
Reply
Cancel
8 on July 5, 2015
#pragma strict
var player : Rigidbody;
function OnCollisionEnter() {
player.velocity = player.velocity*-3* 1.2f;
}

i think its the right code it doesnt work well i see some kind of push when i land on block but it pushes me to -x 

and i want something Like Trampoline u jump and every time u jump u will be punched higher but from all sides 

Guru
on July 5, 2015

Why the * -3 and then again * 1.2 ?

on July 5, 2015

just add like a * 1.2f to the above code

on July 5, 2015

player.velocity = player.velocity*1.2f; this doesnt work either

Guru
on July 5, 2015

What if you try -1.2f ?

on July 5, 2015

i tried all of them first only the script u sent with -1 it doesnt work

on July 6, 2015

just tell me how to find players force that he is coming and i will be good :p

Wise
on July 6, 2015

the players velocity is always player.velocity. to get the reverse of that is player.velocity *-1

and like i said if you are using any of the standard walkers or first person characters or such then they do not allow you to move sideways(because x and z movement is always playerInput * speed.)

on July 6, 2015

nope walk script is solely mine beggining was Brackeys but now it only makes like 10% of code yep sooo its impossible to see players force or something i just wanted to make. if u jump from higher u gonna bounce back even higher like infinite trampoline

Show more replies
  • Liked by
Reply
Cancel