CharacterController Collider Script issue - collider

enter image description here
This script is supposed to End the game if Player hits something infront(z axis). But instead, the Player dies even if it hits anything in x and even y axis(which is ground) so game ends the moment my player touches the ground. Requesting help. I'm new to Unity and c#. So please don't abuse me if the solution is too obvious.

I think the player dies immediately because the ground also have a collider which the player touches. try to add a tag to the object in front the player, and in your code check the tag before calling the end game function.
if(hit.gameobject.tag == "tag" && hit.point.z > transform.position.z + controller.radius)
Death();

Related

Enemies Overlapping in Game Maker: Studio, How Do I Fix This?

The AI of my enemies that I made for my game is simple. They just follow the player (more precisely, they look in the direction of the player and go forward)
Step Event:
if (instance_exists(obj_player)){
direction = point_direction(x,y,obj_player.x,obj_player.y);
}
speed = spd;
But they keep on overlapping each other and go on top of the player. I've tried researching but all the forums said was to use place_free() and xprevious & yprevious, but I have no idea how to use them. How do I fix this?
Thanks :)
You can read about this on the gamemaker documentation : https://docs.yoyogames.com/source/dadiospice/002_reference/movement%20and%20collisions/collisions/place_free.html
basically, what you want to do is avoid moving your instance if that means causing a collision. x_previous and y_previous will be used to cancel the move by going back to the previous position.
But I think it's better to check the place before moving, so I would add at the end of you script :
if (place_free(x+hspeed, y+vspeed)) speed = spd;
else speed = 0;
that way, the ennemy will stop instead of stepping above an other instance.
A little upgrade would be the following : if there is a collision detected, check if you can move along a single axis instead (x or y) and do it.

Client doesn't have a name/class at startup

I'm trying to start an application (Spotify) on a particular tag. Rules aren't applied and now I'm inspecting the client class by printing the class in a notification in the "manage" signal. This results in an empty notification.
client.connect_signal("manage", function (c, startup)
naughty.notify({title=c.class})
end)
When I restart awesome, it does print the client class, so why isn't it working when the client is initially started?
Using xprop, it also prints the class:
WM_CLASS(STRING) = "spotify", "Spotify"
Sounds like a bug in Spotify (and I think I heard about this one before). I would guess that Spotify does not follow ICCCM and only sets its WM_CLASS property after it made its window visible and not before.
I fear that you cannot do much about this except for complaining to Spotify devs to fix their stuff.
You could work around this by starting a timer in the manage signal that checks if a window turns out to be spotify a short time later. Alternatively, you could do something like client.connect_signal("property::class", function(c) if c.class == "Spotify" then print("This is now a spotify window") end end) to react to change to a window's class (of course you'd want to do something more useful to Spotify's windows than printing them).
(Per the ICCCM, a window is not allowed to change its class while it is visible, but who cares about standards...)
I had a similar issue with the claws-mail client. Inspecting it via xprop, it shows
WM_CLASS(STRING) = "claws-mail", "Claws-mail"
but awesome just did’t apply the rules for it. The trick was giving awesome-wm both of these class names in the rules section by providing a set of characters to chose from:
rule = {class = "[Cc]laws%-mail"}
I hope this works for your spotify application, too.
For further reading about patterns in lua I suggest this:
https://www.lua.org/pil/20.2.html

How to make car add points/laps as it goes over finish line?

I am programming a simple top-down car game on game-maker where the purpose of the game is to get as many points/laps by driving the car around the oval shaped track.
The car drives with speed = 5 and changes direction with the code direction = direction + 2;
image_angle = direction;
If you couldn't tell already, i'm new to coding however i have been searching for a solution for at least a fortnight and haven't found anything- How can i make the game add a point every time that the car goes through the finish line? I suppose there would have to be a collision event between the car and the finish line but i do not understand the code that would take place in order to add a point and if I did code the game to add a point i anticipate that there will be a bug where by several points will be added (instead of 1) when the car goes over the finish line as it is "colliding" the whole way as it goes over.
How can I make a point be added every time the car goes around the track?
If you need any further information i'd be glad to help. Thank-you.
With Kake_Fisk's help i set up 3 midway lines around the track and created a collision event between the car and the midway lines: prntscr.com/c4uecl - the problem is that add_point doesn't actually do anything and i would be glad to have some help. Another problem i am encountering is that he car was originally meant to turn with the mouse button 1 but when i tried that the car only turned when i aimed on it if you get what i'm saying, do you have a solution for that also?
obj_car:
creation event:
points = 0; //instance variable
step event:
if(place_meeting(x,y,obj_line)) {
points += 1;
}
if(points == 3) {
room_goto(rm_win);
}
First, you have an other problem you need to think about. What stops the player from just driving forth and back over the goal line? You would need to add invisible lines throughout the track. If all these lines have been passed, you know the player has driven the car through the whole track.
You want to trigger some code once, when the car hits the goal line. By utilizing the previous system, this can be done quite easily. In collision with goal line, use something like this:
// If all the invisible lines in the track has been visited
if (midway_lines == 3)
{
// Sets the variable back to 0 so this piece of code only gets executed once
midway_lines = 0;
add_point();
}

Send future clients to right monitor in awesome?

I'm trying to implement a very customized implementation of awesome.
I have two monitors. I'd like to have my first client always open on the left monitor (a Chrome window in kiosk mode), then all clients after open up on the right monitor.
Are there any custom layouts that accomodate this?
I'd be willing to program it myself, but I'm not sure how to bind a script to some kind of "new client" event.
The new client event is the manage event. It is emitted whenever, well, a new client gets managed by awesome.
To send the first client that ever appears to screen 1 and all following ones to screen 2, you could do something like this:
local first = true
client.connect_signal("manage", function(c)
if first then
c.screen = 1
else
c.screen = 2
end
first = false
end)

GML -> check for a colliding instance's variable, then do action

I've been trying to do some GML scripting but got totally stuck at some point.
I want enemies to attack my main character but without overlapping. So, I would say.
//enemy is moving left-to-right...
if place_meeting(x+1, y, enemy){ //if there's a collision with another enemy
if (other enemy).is_attacking{ // ???
// checks if the colliding enemy is attacking, if true, it should attack as well...
is_attacking=true;
}else{
//walks
}
This is an image that describes what I'm trying to get (note that enemies know they should be attacking even though they're not in direct contact with the main character, just because an enemy besides is attacking)
I was finally able to do it thanks to the instance place function.
I will post the code in case someone need somethin similar
if place_meeting(x+5, y, malo){ //malo means enemy on spanish, i use to write multilingual code, lol :P
var inst;
inst=instance_place(x+15,y,malo); //x varies on sprite size. it basically returns the unique id of the object that's 15 pixels on the right of self (malo)
with (inst){
if (is_attacking){
other.is_attacking=true; //if collided enemy is attacking, then this(other) enemy should attack too. search more about the width statement if you don't catch this part
}else{
other.is_attacking=false;
hspeed=1;
}
}
}else if place_meeting(x+3, y, character){
is_attacking=true;
}else{
is_attacking=false;
hspeed=1;
}
and the result

Resources