Basic Gravity?

BlitzMax Forums/MiniB3D Module/Basic Gravity?

Yahfree(Posted 2010) [#1]
Hey, I haven't touched 3d in a lonngggg time.. and when I did I only played with terrain.

This time I have a mesh level (a tunnel to be exact). The tunnel is basically a flipped multi-extruded box that had been sub-divided. AKA, it's an interior level.

So right now I have a roaming camera, and the mesh looks great.. but I don't remember how to stick the player to the bottom of the mesh so i can walk around the tunnel with a sense of gravity. I'm not interested in jumping right now.

here's my code:


Thanks!


Sledge(Posted 2010) [#2]
Set up collisions between the entities and translate downwards to simulate gravity. UpdateWorld() to enact collision responses.



Next you will probably want to make your camera a "head" that is childed to a "body" entity, the latter being subject to collisions rather than the former so the player can look around while moving forward.


Yahfree(Posted 2010) [#3]
How do you create a body entity and subject that to collisions? Also how do you define how tall the entity is so the camera can be elevated off the ground?


Sledge(Posted 2010) [#4]


And you're welcome.


Yahfree(Posted 2010) [#5]
"And you're welcome. "

Thanks!

You didn't mean that I'm coming across as rude or anything did you? I just realized that i didn't say thank you in my reply although I swore I did.


Sledge(Posted 2010) [#6]
It's not up to me how it comes across, is it?! Anyway it's an easy oversight and you are most definitely welcome -- ask away if you have any more probs.


Yahfree(Posted 2010) [#7]
hehe,

So now I have three questions that I'm sure you're anxious to answer:

1.) how do I lock the mouse in the center of the screen and still allow camera movement with the mouse (FPS style)?
2.) When my player dies, I want him to reset in the starting location. How do I do this, because PositionEntity doesn't seem to work?
3.)The zombie AI is basic, but a problem already has occurred: I have him pointing towards the player and moving forward, simple enough, but he also points up and down, which I don't want. How do I lock him into rotating only on the y axis (spinning around horizontally)?

here's my current code:



*(Posted 2010) [#8]
1) when doing this I normally do MoveMouse to move it to graphicswidth()/2, graphicsheight()/2 this does the trick :)

2) Place a pivot entity at the start point and reposition the player at that point and facing direction, PositionEntity is good for this :) and it does the trick perfectly

3) Rotate the Zombie to 0.0, EntityYaw( Zombie ), 0.0 this should solve it :) Where Zombie is the entity for the zombie :)


Yahfree(Posted 2010) [#9]
3 looks like it should work.

1) I tried this, but it doesn't allow for fps camera movement as I use MouseXSpeed and MouseYSpeed for movement, and the mouse being reset gives a mouse direction which doesn't allow the camera to move.
2) Not sure I get this.. how do I place something at that pivot? I've tried PositionEntity player, -600, 700, 0 .. it doesn't work.

Thanks!


ima747(Posted 2010) [#10]
1) get the difference between mouseX/mouseY and the center before reseting.
local mouseDiffX:int = MouseX() - (GraphicsWidth()/2)

and use the mouseDiff variables to tell how much it moved between frames. remember to reset right after you calculate the difference or you could lose some difference between frames.

2) You have to call ResetEntity() on the player after you call positionEntity and before your next call to update world. This effectively turns off their collision for one update, allowing you to position them without then getting stuck on something along the way.
'reset player
PositionEntity(player, -600, 700, 0) ' put him back at the start
ResetEntity(player) ' no collisions this frame for player
... ' stuff happens
UpdateWorld() 


3) I'd do this just like ed, here's a slightly more readable example just for clarity
PointEntity(zombie, player) ' point the zombie at the player
RotateEntity(0.0, EntityYaw(zombie), 0.0) ' set the pitch and roll to 0, while keeping the existing yaw



Kryzon(Posted 2010) [#11]
@ #1 - try to read the velocities before moving the mouse:

mx# = MouseXSpeed()
my# = MouseYSpeed()

MoveMouse GraphicsWidth()/2,GraphicsHeight()/2



Yahfree(Posted 2010) [#12]
Cool, thanks.

For creating multiple instances of an object (say a zombie), is it better to call "loadmesh" for each instance, or do something like hide a mesh and use "copymesh" off of that?


ima747(Posted 2010) [#13]
Look into CopyMesh and CopyEntity, depending on what you want to do with it once you've copied it (manipulate the mesh or just have one that looks the same you can move around etc.) you want to avoid loading things again if you've already got them loaded as a general rule to save time and memory.


Yahfree(Posted 2010) [#14]
Thanks!

Another question.. man I'm full of them aren't I?

How come my zombies won't collide with each other?

Here's my zombie type:


As you can see, in the creation I use "EntityType handle,3" and this is what I use for collision between zombies:

Collisions(3, 3, 2, 3)


however, this doesn't seem to work because the zombies stack on top of one another when chasing the player... Am I doing this wrong? (obviously)

Oh, and just a side note, not really important at the moment, but it seems that these zombie copies do not animate, any reason why?


Sledge(Posted 2010) [#15]
You needed to use sphere-to-sphere collision to handle the situation where several of your colliders were in motion in Blitz3D, however the last time I checked it didn't work for this purpose in MiniB3D.

You could move each zombie in turn, running an UpdateWorld() between each, but that will kill your performance; The only other thing that springs to mind is using a physics lib.

However, try Collisions 3,3,1,2 first as things might've been updated since I last used this stuff.