Physics Help for a Game

physics

#22

I can’t do ‘When touching (air)’. I wish there was a ‘When not touching’.


#23

Are you gonna use my code?


#24

The blocks themselves need to do the collision testing since they have access to their own attributes.

Block_size = e.g 40 

When abs(player.y - self.y) < block_size:
  player.yvelocity = player.yvelocity * -0.8

When abs(player.y - self.y) < block_size:
  If player.y > self.y:
    Set player.y to self.y + block_size
  Else:
    Set player.y to self.y - block_size

...and the same for x.

This method uses no bump blocks.


#25

Thanks! Just wondering though, what code would I put into the ‘Player’ object to make it adhere to what the terrain was telling it to do?


#26

Make a variable: when [(self)is on ground] set [(self)vertical velocity] to 0
And make a variable called Y, which is the Y position of the character, and increase that variable by your vertical velocity, when you make that, make the collisions COAN already said but add the Ypos variable, when [PlayerY-selfY]<40
Set [(player)is on ground] to 1
Check once if playerY<SelfY+33
Increase playerY by 1


#27

Just some basic physics:
Each of these should be in a separate 7=7/repeat forever
Increase player.y by player.yvelocity
Increase player.x by player.xvelocity
Increase player.yvelocity by -1 (gravity)


#28

Thanks! I’ll try and implement it!


#29

I’m fairly sure I did it right but it is really not working…
Could you please check if I have done anything wrong?


#30

/ is divide, * is multiply


#31

You’ll just need to check if the block is invisible.
Like ”when (y thing) and invisibility=0”


#32

Oh. Yeah. Thanks… Duh. :no_mouth:


#33

Sorry, forgot another thing. You’ll also need to check if the player is close on the x plane.
So like this: when abs(ypos-self.ypos) < 25 and abs(xpos-self.xpos) < 25 and invisibility=0

@MISSION_IMPOSSIBLE look at this post


#34

Hang on… I always land on air at the highest point of the terrain, just floating.


#35

I really appreciate all your help, but it still isn’t quite working.
https://c.gethopscotch.com/p/10114i5u1k


#36

That’s because you haven’t added the x part. Just copy the physics code for y (you can hold down on the custom rule and copy it) and change it to x.


#37

I did though.


#38

Yeah, for the y collision detection.
But I was meaning a whole new custom ability with the same code as the current but with all the set y and set yvelocity changed to set x and set xvelocity.


#39

Okay, maybe I am being stupid but I cannot for the life of me get this thing to work. I did exactly what you said. Could you please make a copy of one of my projects and put in the physics and then I can try and implement it into my own version and see where I went wrong?


#40

Ok. There might be an easy fix: I got it to work by changing the collision detection variable a bit (I believe it’s 25). For the x bouncing I increased the x detection by 1 and the y detection by -5.
For the y bouncing I increased the x detection by -5 and the y detection by 1.
This might work


#41

What’s wrong here?
https://c.gethopscotch.com/p/101157jv4a