Im tring to get a collision to output while allowing the objects to overlap Csharp, any ideas appreciated.
public float PlatformSpeed = 0.04f;
void OnCollisionEnter2D(Collision2D col) {
if (col.collider.gameObject.tag == "Player")
GameObject.Find("Player").transform.Translate (PlatformSpeed, 0, 0);
This is the collison script im working with, in a sense it works, atleast it runs and it does move my player, but only if the platform hits my player first, if i jump onto the platform i just sorta sit by the side of the object, the only way i know to allow them to overlap is by changing one to 'is trigger' but then it doesnt output, been stuck for a while now so any and all help will be much appreciated.
Hopefully you see what im trying to do, thanks for taking a look :)
Answer by sumitb_mdi · Dec 13, 2016 at 02:55 PM
Yes you are correct, that if you want them to overlap, you need to change those colliders to Trigger Colliders. After that all you need to do is change your method From :
void OnCollisionEnter2D(Collision2D col)
To :
void OnTriggerEnter2D(Collider2D other) {
//Your logic here with other.gameObject.
}
ok, well firstly, thanks for the reply, appreciate it!
But i tried what you wrote me, and while the player can now jump onto my platform, he doesnt move... i do want to check, should the trigger be the platform or the player because making the player the trigger will mess up loads of other scripts.
Also just for reference the script is to be attached to the platform as i have multiple platforms all moving at different speeds.
Just to make sure that i got it right, heres my newly modified script...
public float PlatformSpeed = 0.04f;
void OnTriggerEnter2D(Collision2D other) {
if (other.collider.gameObject.tag == "Player")
GameObject.Find("Player(Frog)").transform.Translate (PlatformSpeed, 0, 0);
print ("HIT!");
}
Thanks again!
Also, sorry if ive done something obiously dumb here, im very new to all this
Can't get what you are trying to accomplish here. If you want I can help you over Skype with these scripts, that would be faster ins$$anonymous$$d of guessing what you are trying. (SkypeId: sumitb.mdi)
To be honest, i appreciate you trying to help me but im a bit funny about adding random people on skype, even for my own benefit. but if this helps im basically re-creating frogger, and im trying to make it so that the frog can jump onto the logs and move at the same speed as the logs.
in theory, what im trying to achive witht the code i have is...
if player (Frog) is touching the log then move the player at "platformspeed"
appreciate you helping me all the same thanks :)
Your answer
Follow this Question
Related Questions
How to learn loading/pressure/compression on a 2D body? 0 Answers
How to Change players Desktop Background C#? 1 Answer
Cant Get Simple Boolean Statement to Work! 1 Answer
Simple Camera Switch Using C# 3 Answers
2D Object Spawn Lag 1 Answer