How to make my character invisible just after he gets in the car?

Hi, after one year trying to find out how to make a GTA game, i finally make my character enters the car do the animation of openning the door and the car aniamtions as well. All this using 2 Near sensors only, one in my character’s Cube that is conneted with an action actuator in my character so when i hit the X key (That will be the key to enter and get out the car) and one in the cube that moves my car conected to an actuator so when you are close to a car and press X as soon as the character is opening the car door, the door will be open (Shapekey animation) as well and a property with the name Playable, so when i press Xkey the value of playable will be 2, and when property playable is = 2 all the sensors that moves the car will be activated.
See, reading this looks so complex, but the real thing, is not so much … what i want to do now is once the character finish the animation of getting in the car, i want my character to dissapear and when i press the xkey to get out of the car, he appears again. How can i do this? How can i make my character visible when animation ends? This because the animation is made with logic bricks, i don’t know how to make Near sensor works on python. It will be easier with python but hey, what the heck, i always want to try the hardest method first :wink: hehe

If you don’t want to use python, I would use states. Rather than having your near sensors execute an animation, have them switch to an “enter car” state that only plays the animation and has a delay sensor. Once the delay sensor triggers, move to another state “in car” that sets the visibility.

There are also ways to check for the end of an animation but if the animation is always the same length, a new state with a delay sensor would probably be the easiest.

and how it would be the python script, don’t worry i’m not a newbie on python no more, so i’m a little advance … not profesional, just say, average. I’m imagining what you say already :slight_smile: and it sounds logic to me :slight_smile: … so this i can make with a state actuator huh? pretty easy i think, i’ll try your advice, anyway i’m going to post the .blend file just in case you wanna see what i’m doing.

If using python, you could get the actionframe and set the object’s visilibity. (You actually don’t HAVE to use python for this but it is a lot easier). So if your animation was 120 frames, it would look something like this.

if round(armature.getActionFrame(0)) == 120:
    player.visible = False

The reason I use ‘round’ is that action frames aren’t integers and might not always land perfectly on 120. Also, the 0 is the layer of the action.

I suggest to completely remove the character. You do not need it while driving. This way it it does not eat resources.
You can add the character again, when you want ut leavibg the car.

that’s … veery interestent!!! is actually easier to do that on python … otherwise, how to make my near detect an object with “car” property inside python? i personally will add an VAR called playable, and a property called playable also. I think the script would be like this right?:

if XKEY == 1 and Near.positive :

g.playable = 2

act.action = “opne car”
act.frameStart = 1.0
act.frameEnd = 400.0
act.blendIn = 0
act.mode = 0 (i think 0 is Play mode)
co.activate (“Action”)

if o[Open car]=True ####(defined on properties of course) ####### and o[frame] == 400.0 :

character.visiblity = false

Well, that’s the script i planned, i will join together the three objects mentioned before, Armature (where is the python script) the Character and the Cube (where is the Near sensor)

Avoid nummeric constants in code. They are hard to read. Better use the descriptive constants of the API.

Avoid short or cryptic names such as o, g, act. They are hard to read and can easily be confused or misinterpreted. Better use full length descriptive names such as object, action, actuator. You have a computer that supports text input pretty much. You can even do copy and paste.

Btw. Why you want to detect near with python? The sensor does that already, you just ask if all sensors are positive and your code does not even need to know what sensors that are.
The Python controller is not exclusive. No need to do everything in Python. Better implement the operations in Python that really need that.

Rather than using near sensors, I would cast a short ray in front of the character on key press and then do your “enter car” logic if the hit object is a car. If you have a near sensor for every car, that might get a little expensive performance wise. (Not sure about this, haven’t tested how performance heavy near sensors are) Also, this would prevent being able to enter cars if they are behind the player.

Add an empty in front of the player and parent it to the player object.

Example code:

enter_car_dist = 10

if x_key.positive:
    hit_object = own.rayCastTo(raycast_empty, enter_car_dist, "car")

    if hit_object != None:
        own.state = 1<<1
        hit_object.state = 1<<1

The code above assumes A LOT and will do nothing unless set up correctly. It’s just to give you an idea of a different way of doing things. It assumes you would have a second state for the player (enter car) and the car (begin drive mode).