Character/Vehicle

Blitz3D Forums/Blitz3D Beginners Area/Character/Vehicle

Blitz3dCoder(Posted 2007) [#1]
I have tried to do this, but nothing has worked.

Ok, I have a character, and a vehicle, I want him to get into the vehicle, by pressing the 'd' key when he is 1 blitz unit away from the vehicle.
I have messed with the entity distance command, and hideentity and stuff, I just cannot get anything to work.


big10p(Posted 2007) [#2]
EntityDistance should work fine for checking whether the character is near enough to the vehicle, or not.


boomboom(Posted 2007) [#3]
probably going to have to post up some code


Blitz3dCoder(Posted 2007) [#4]
Here is the car
VEHICLE1=LoadMesh("f360.3ds")
Cartex=LoadTexture("fskin.jpg")
EntityTexture VEHICLE1,Cartex
PositionEntity VEHICLE1,-22,6,202
ScaleEntity VEHICLE1,2,2,2
EntityRadius VEHICLE1,.2
EntityType VEHICLE1,Car

Here is the character
char=LoadAnimMesh("dwarf2.b3d")
chartex=LoadTexture("dwarf2.jpg")
PositionEntity char,-50,6,120
ScaleEntity char,.085,.085,.085
EntityType char,Player
EntityRadius char,.2


dont laugh
If EntityDistance (char,VEHICLE1)<1 And If KeyDown(32) Then 
EntityParent VEHICLE1,char
HideEntity char
End If 

also, how do you change the controls that normally control the character to control the vehicle

I am doing this project to learn how to do the stuff, so if you recognize the names of the meshes from psionic, I am just using them as place holders.


big10p(Posted 2007) [#5]
If EntityDistance (char,VEHICLE1)<1 And If KeyDown(32) Then
Does that even compile? Try:
If EntityDistance (char,VEHICLE1)<1 And KeyDown(32) Then



Blitz3dCoder(Posted 2007) [#6]
I just typed it up now, since I deleted the original, that if doesn't belong there.

My code definatly does not work, I put what I put on the post again, and made sure, I did not put the second if in there, and nothing happened at all.


*(Posted 2007) [#7]
why not make the vehicle pickable then do an entitypick and if they can pick the truck and they are within one unit then they can get in


Blitz3dCoder(Posted 2007) [#8]
I know even less about that

Is there any way to do it that is closer to this:
If EntityDistance (char,VEHICLE1)<1 And KeyDown(32) Then 
EntityParent char,VEHICLE1
HideEntity char
End If 



SLotman(Posted 2007) [#9]
well, maybe the char are further away than "1" from the vehicle? Run the code in debug mode, and add the line

debuglog "distance:" + entitydistance(char,vehicle1)

also change your if to:

If KeyDown(32) Then 
   If EntityDistance (char,VEHICLE1)<1 then
      ; do your stuff here
   end if
end if


why? because entitydistance takes time - of course on a simple example it wouldn't matter, but if you do several calls on every loop, things will slow down.

So changing the If's you'll only check when the user press the apropriate key, instead of checking all the time...


Ross C(Posted 2007) [#10]
Entitydistance is fine to use many many hundreds of times. It's a very simple calculation. What might be happening is the distance you have specified is less than the collision radius of the car. Try setting a bigger value.

To do with the code part, try structuring the code using a mode variable:

If mode = 1 then
   ;do controls for walking
ElseIf mode = 2 then
   ;do controls for vehicle driving
End If



jhocking(Posted 2007) [#11]
To clarify what both Slotman and Ross pointed out, bear in mind that EntityDistance is calculating from the center of the entity (or rather the origin point, which is typically somewhere in the middle) not from its outside edge. Thus, if the vehicle is bigger than 1, then the character is never actually getting close enough.

So yeah try setting the distance check to a bigger value and see if that works.


Vorderman(Posted 2007) [#12]
Remember that one of the entities is an ANIMMESH - it may be that the child mesh that is the actual visual character is not near the centre of the entity.

Try finding the anim mesh's child that is the visual mesh, then using entitydistance on that.


Blitz3dCoder(Posted 2007) [#13]
Here is the entire code for this project.


Edit: I changed the <1 to <5, and when I went inside the car, (screwed up collision, will fix) and pressed 'd' like 5 times it screwed up the text in the top left hand of the screem? Why?




SLotman(Posted 2007) [#14]
Well, I just had a quick look but this:

Collisions Player,Obstacle,2,2
Collisions Obstacle,Player,2,2
Collisions Ground,Player,2,3
Collisions Player,Ground,2,3
Collisions Player,Car,2,3
Collisions Car,Player,2,3
Collisions Car,Ground,2,3
Collisions Ground,Car,2,3


should NOT be in your main loop. You just declare it ONCE, and it will work until you call clearcollisions or something.


Ross C(Posted 2007) [#15]
SLotman is right, you shouldn't be doing that. Also, you should try and make your variables global.

<img src="http://blitz3dstuff.googlepages.com/untitled.JPG">


Does that even compile? Seems like Web Browser code.

Try throwing in a cls at the top of your loop. Shouldn't really do anything as renderworld should overwrite the whole screen.

You should try stripping your code down o the very basics of what you need to make it work. You don't need the weapons shop or anything like that :o)


puki(Posted 2007) [#16]
I love Blitz - where else could you find someone trying to get a dwarf to drive a ferrari?


Blitz3dCoder(Posted 2007) [#17]
Ross c
I have no clue how that html got in there, I have been doing that lately too, so, it was probably on my clipboard...

Puki, I try to do new things. I have an animated horse model to, but I thought a ferrari would be cooler. It is just for fun and to learn, so I figured that I could do what I wnat


Blitz3dCoder(Posted 2008) [#18]
I decided to get back to this project as i did not ever figure out how to get that code to work. I noticed something when going back through, the collisions for the car only work on the top of the car (if i jump up on top i dont fall through) but it lets me walk right through the side of the car except for the wheels what the heck


Blitz3dCoder(Posted 2008) [#19]
No matter what mesh i try to hide with hideentity, it always freezes the game, and screws of the lettering, and does not hide anything.


Doggie(Posted 2008) [#20]
@puki
Speaking of a dwarf in a Ferrari...uh.on second thought, better not. Never mind.


Blitz3dCoder(Posted 2008) [#21]
Got some advice?


Ben(t)(Posted 2008) [#22]
did you mention you were having trouble with moving once you were in the car?


Blitz3dCoder(Posted 2008) [#23]
no, i got the moving down, but here are my problems:

The collision only works on the wheels, and the top of the cars (got another one, both from psionic)

and, hideentity will not work, it always screws up the text , (view picture) and it makes the game freeze, and it does not hide anything, and

I cannot get the camera to rotate on the x (does pointentity camera, do this maybe?

also, when i drive over something bumpy, the character seperates from the car even though it is parented to the car.

Do you want me to submit some more recent code?


PowerPC603(Posted 2008) [#24]
Instead of hiding the entity, can't you just unload it (FreeEntity)?

And when you have your character parented to the car, you can remove the collision-type from your character and just keep the collisions on your car.
That way your character doesn't bump into obstacles ( since it doesn't have collisions anymore) and will stay in place.


Blitz3dCoder(Posted 2008) [#25]
is that what it would be?


Collisions Ground,Player,2,3=false
Collisions Player,Ground,2,3=false


Ben(t)(Posted 2008) [#26]
do the cars have bottoms?


Ross C(Posted 2008) [#27]
Can't you just parent the dwarf to the car, and then hide it. Then just move the car?

Can you post the put a file with your code and all the media up and i'll have a look see.


PowerPC603(Posted 2008) [#28]

is that what it would be?


Collisions Ground,Player,2,3=false
Collisions Player,Ground,2,3=false



To remove collisions from an entity, set it's entitytype to 0, then no collision-checking will take place (see documentation about EntityType).
When the player gets out of the car, re-initialize the EntityType of the player (EntityType char,Player).


Blitz3dCoder(Posted 2008) [#29]
All right, here is the file Click this


H. T. U.(Posted 2008) [#30]
The collision only working on the wheels may be because the model isn't made into one group. If it isn't, Blitz might treat each group as a separate entity.

Though I'm not certain what is screwing up the text, it might be fixed by clearing the screen at some point in the main loop, maybe after the Flip command.

You might be able to do away with the problems with HideEntity by clearing the collisions for the dwarf and setting his alpha to zero while he is in the car. But I haven't tested this yet.

OK, this is a REAL wild guess, but the problems your having with the camera's rotation and with the messed up text may be related. I don't use parents very much because of the problems I have using them. I usually set the child's position to that of the parent and then move and rotate it to the position and direction I want. I've noticed that sometimes when a parent isn't moving the child will resist moving and also give strange position and orientation results.


Ross C(Posted 2008) [#31]
Ok, i have had a look at this.

Firstly, your jeep and car are made out of many parts. They aren't centred either, so this is causing some collision issues. When using entitytype, using the recursive flag so it sets all parts to have collisions.

Same problem with your shop i believe

For some reason your camera was pointing downwards?

Try and give all your extracted animations a variable assignment. Makes it easier to keep track of whats what :o)

Indent your code better. Every IF statements contents should probably be indented by al least a tab. Keeps it consistant and easily readable.

Make your variables GLOBAL if you intend to use them throughout your code. If you add functions to that code, many of your variable setting would be over written, or worse, shared.

I shared your problem with hideentity. Not sure what that was about, but i buggered something up. Problably a variable problem.

I implemented a better camera system, one that doesn't rely on setting up a parent. You simply pass across the entity you want the camera to follow every frame. You can change entities and it will smoothly translate.

You need to put your vehicles into a type collection, or array system (Types are easier to read). Reason being, you have hardcoded variable names and don't really know how many vehicles you have, or have any easy way of individually checking them. I have implemented a type system to hold your cars. When the SPACEBAR is pressed, it does a distance check against all the cars and returns the closest car. You simply do a distance check against the returned entity to see if it is in range or not.

I put alot of stuff into functions to ease reading and enable you to see whats going on better.

I think that's all. I completely rewrote your code too, sorry about that, but it's easier for me to do that than try and modify yours :o) I haven't commented everything, just the things i have really changed.

Oh, i added a speed variable to your vehicles, so they accelerate and decelerate. Pretty basic stuff. Just to get you started.




Blitz3dCoder(Posted 2008) [#32]
You did not have to spend that much time, thanks, ill have a look


Blitz3dCoder(Posted 2008) [#33]
Dang, that is better, thanks, ill study it.
No problems, except, he is kinda hovering about the ground now, Ill work on it.


Ross C(Posted 2008) [#34]
I increased his entityradius, so it's probably forcing him off the ground a little. As i say, it's pretty basic as collisions and such go.