Rotate an object based on the object it collides
Blitz3D Forums/Blitz3D Programming/Rotate an object based on the object it collides
| ||
I'm making a 3D game and I realised one thing - If I go up ramps & irregular surfaces with my little character, it stays up, not rotating based on the object underneath it. If that didn't make sense, here's a picture to explain. Pictures do explain a lot. xD ![]() I'm hoping to finish a Sonic game for a friend of mine (and SAGE) as a first effort in making ANY 3D game! Physics and everything is a pain in the neck. Always the thing that gets in my way. -.- Anyways, thank you for reading! I'd be so happy if anybody got an answer for this Q! :3 |
| ||
try using "Aligntovector" command here: http://www.blitzbasic.com/b3ddocs/command.php?name=aligntovector&ref=goto there are some samples too... try tweaking them |
| ||
;linepick example by RossC Graphics3D 800,600 SetBuffer BackBuffer() Global camera = CreateCamera() Global light = CreateLight() Global player = CreateCone() EntityType player,1 EntityRadius player,1 EntityColor player,50,70,255 PositionEntity player,0,0.5,0 Global cam_piv = CreatePivot(player) PositionEntity cam_piv,0,2,-8 Global tex=CreateTexture(64,64,1+8) SetBuffer TextureBuffer(tex) For loop=0 To 3000 Color Rnd(190,255),Rnd(190,255),Rnd(190,255) Rect Int(Rnd(0,63)),Int(Rnd(0,63)),1,1 Next Color 255,255,255 SetBuffer BackBuffer() Global plane=CreatePlane() EntityType plane,2 EntityColor plane,200,100,120 EntityTexture plane,tex EntityPickMode plane,2 Global sphere=CreateSphere(10) ScaleEntity sphere,10,3,10 EntityPickMode sphere,2 EntityType sphere,2 PositionEntity sphere,-2,0,19 Collisions 1,2,2,2; set up collisions between the ground and the player Global jump_force# Global jump_flag=0; set jump flag to 'no jump' Global gravity#=0.9; set gravity value While Not KeyHit(1) ; this part is the linepick. The tform part, is to make sure the linepick is done from the players ; actual rotation, straigh down. TFormVector 0,-10,0,player,0 ; the values from the tform then get used in the linepick command. if you just substitute your ; variable for the player into here, everything will be cool! LinePick(EntityX(player,True),EntityY(player,True),EntityZ(player,True),TFormedX(),TFormedY(),TFormedZ()); do a linepick straight down form the players location ; aligns the player to the scenery, whatever has has a pickmode set. AlignToVector player,PickedNX(),PickedNY(),PickedNZ(),2,0.1 If KeyDown(200) Then MoveEntity player,0,0,0.1 If KeyDown(208) Then MoveEntity player,0,0,-0.1 If KeyDown(203) Then TurnEntity player,0,1,0 If KeyDown(205) Then TurnEntity player,0,-1,0 update_camera() UpdateWorld RenderWorld Text 0,0," Press Space to jump. Arrow keys to move!" ;DebugLog(" pickedy="+PickedY()) Flip Wend End Function update_camera() PointEntity camera,cam_piv MoveEntity camera,0,0,EntityDistance#(camera,cam_piv)/40.0 PointEntity camera,player End Function ;;======= It's from the forum... from ROSSC .. study it.. and credit ;;him(if you like) |
| ||
Thank you! It works perfectly! My character could go up loops now. It's something that used to bother me a lot. |
| ||
you're welcome TomFeatherhill ! i think the forum is created for this purpose .. :) |
| ||
well, i hope i wont run into guys that you talk about, Guy Fawkes.. |
| ||
You ...literally... just derailed someone's thread, with absolutely no intention of helping them, specifically for the purpose of picking a fight with other forum users, and you think other users here are the ones holding a grudge? |
| ||
Right, ignoring that last comment above, You're going to want to use AlignToVector. Also, make sure that when you use collisions, you use a sliding collision so that the character slides back down the hill at a certain angle. |
| ||
Right, ignoring that last comment above, You're such a stupid kid - why can't you ignore something without telling the world you are ignoring it? There must be 100 posts over here telling us that you are ignoring something or someone ... Do you even know what ignoring means? |
| ||
I would attach child pivots to the corners and reorient the parent based on position of these. BTW, I'm pretty disappointed with the above, this is a programming forum GF please respect that. |
| ||
...you use a sliding collision so that the character slides back down the hill at a certain angle. Note taken. I think that's the reason why the loops in my game glitch a bit. I would attach child pivots to the corners and reorient the parent based on position of these. I would use this when my Character goes on stormy seas and everything. I guess I'd do the same for a car that goes down the stairs. Thanks once again! |